Advertisement
mirozspace

Untitled

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