Dido09

06.ChristmasDecoration

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