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