Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Problem_06 {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- double budget = Double.parseDouble(scanner.nextLine());
- String input = scanner.nextLine();
- while (!input.equalsIgnoreCase("STOP")) {
- int price = 0;
- for (int i = 0; i < input.length(); i++) {
- char currentSymbol = input.charAt(i);
- if (Character.isAlphabetic(currentSymbol)) {
- price += currentSymbol;
- budget -= price;
- }
- }
- if (price < budget) {
- System.out.println("Item successfully purchased!");
- } else {
- System.out.print("Not enough money!");
- break;
- }
- input = scanner.nextLine();
- }
- if (input.equalsIgnoreCase("STOP")){
- System.out.printf("Money left: %.0f",budget);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement