Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class ChristmasDecoration {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- int budget = Integer.parseInt(scanner.nextLine());
- String input = scanner.nextLine();
- while (!input.equals("Stop")) {
- int price = 0;
- for (int i = 0; i <= input.length() - 1; i++) {
- price += input.charAt(i);
- }
- if (budget - price < 0){
- System.out.println("Not enough money!");
- break;
- }
- budget -= price;
- System.out.println("Item successfully purchased!");
- input = scanner.nextLine();
- }
- if (input.equals("Stop")){
- System.out.println("Money left: " + budget);
- }
- }
- }
Add Comment
Please, Sign In to add comment