Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.company;
- 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 command = scanner.nextLine();
- while (!command.equalsIgnoreCase("Stop")) {
- int wordLength = command.length();
- int itemPrice = 0;
- for (int pos = 0; pos < wordLength; pos++) {
- int asciiValue = command.charAt(pos);
- itemPrice += asciiValue;
- }
- if (itemPrice <= budget) {
- System.out.println("Item successfully purchased!");
- budget -= itemPrice;
- } else {
- System.out.println("Not enough money!");
- return;
- }
- command = scanner.nextLine();
- }
- System.out.printf("Money left: %d", budget);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement