Advertisement
mark79

Christmas Decoration

Oct 26th, 2019
453
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.91 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.  
  7.         int budget = Integer.parseInt(scanner.nextLine());
  8.  
  9.         String input = scanner.nextLine();
  10.         while (!input.equals("Stop")) {
  11.             int itemPrice = 0;
  12.             for (int i = 0; i < input.length(); i++) {
  13.                 itemPrice += input.charAt(i);
  14.             }
  15.             if (budget - itemPrice >= 0) {
  16.                 System.out.println("Item successfully purchased!");
  17.                 budget -= itemPrice;
  18.             } else {
  19.                 System.out.println("Not enough money!");
  20.                 budget -= itemPrice;
  21.                 break;
  22.             }
  23.  
  24.             input = scanner.nextLine();
  25.         }
  26.         if (budget > 0){
  27.             System.out.printf("Money left: %d", budget);
  28.         }
  29.  
  30.     }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement