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