Advertisement
mimisimi

Коледна украса

Dec 23rd, 2018
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.01 KB | None | 0 0
  1.  
  2. import java.util.Scanner;
  3.  
  4. public class Problem_06 {
  5.     public static void main(String[] args) {
  6.         Scanner scanner = new Scanner(System.in);
  7.         double budget = Double.parseDouble(scanner.nextLine());
  8.         String input = scanner.nextLine();
  9.  
  10.         while (!input.equalsIgnoreCase("STOP")) {
  11.             int price = 0;
  12.             for (int i = 0; i < input.length(); i++) {
  13.                 char currentSymbol = input.charAt(i);
  14.                 if (Character.isAlphabetic(currentSymbol)) {
  15.                     price += currentSymbol;
  16.                     budget -= price;
  17.                 }
  18.             }
  19.             if (price < budget) {
  20.                 System.out.println("Item successfully purchased!");
  21.             } else {
  22.                 System.out.print("Not enough money!");
  23.                 break;
  24.             }
  25.             input = scanner.nextLine();
  26.         }
  27.         if (input.equalsIgnoreCase("STOP")){
  28.             System.out.printf("Money left: %.0f",budget);
  29.  
  30.             }
  31.     }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement