Advertisement
Valeri12580

06. Christmas Decoration

Jan 1st, 2019
318
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.80 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Exercise6 {
  4. public static void main(String[] args) {
  5. Scanner scanner = new Scanner(System.in);
  6. int budjet = Integer.parseInt(scanner.nextLine());
  7. String predmet =scanner.nextLine();
  8.  
  9.  
  10. while (!predmet.contains("Stop")) {
  11. int sum=0;
  12.  
  13. for (int i = 0; i <predmet.length(); i++) {
  14. sum=sum+predmet.charAt(i);
  15.  
  16. }
  17. budjet-=sum;
  18. if (budjet>=0){
  19. System.out.printf("Item successfully purchased!%n");
  20.  
  21. }else{
  22. System.out.printf("Not enough money!");
  23. return;
  24.  
  25. }
  26.  
  27. predmet = scanner.nextLine();
  28.  
  29.  
  30.  
  31. }
  32. System.out.printf("Money left: %d",budjet);
  33.  
  34. }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement