Advertisement
Lyubohd

Christmas Decoration

Feb 21st, 2019
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.93 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Demo {
  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 command = scanner.nextLine();
  10.  
  11.         while (!"Stop".equals(command)) {
  12.             int price = 0;
  13.  
  14.             for (int i = 0; i < command.length(); i++) {
  15.                 price += command.charAt(i);
  16.             }
  17.  
  18.             if (price <= budget) {
  19.                 budget -= price;
  20.                 System.out.println("Item successfully purchased!");
  21.             } else {
  22.                 budget -= price;
  23.                 System.out.println("Not enough money!");
  24.                 break;
  25.             }
  26.  
  27.             command = scanner.nextLine();
  28.         }
  29.  
  30.         if ("Stop".equals(command)) { // other way   if (budget >= 0) {
  31.             System.out.println("Money left: " + budget);
  32.         }
  33.     }
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement