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