galinyotsev123

ProgBasicsExam22and23December2018-E06christmasDecoration

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