Advertisement
damesova

Christmas Decoration - Java

Dec 30th, 2018
224
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.87 KB | None | 0 0
  1. package ExamPB22Dec18;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class Task_6 {
  6. public static void main(String[] args) {
  7. Scanner scanner = new Scanner(System.in);
  8.  
  9. int budget = Integer.parseInt(scanner.nextLine());
  10.  
  11. int rest = 0;
  12.  
  13. while (true) {
  14. String input = scanner.nextLine();
  15. if (input.equals("Stop")) {
  16. System.out.printf("Money left: %d", budget);
  17. break;
  18. }
  19. int sum = 0;
  20. for (int i = 0; i < input.length(); i++) {
  21. sum += input.charAt(i);
  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. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement