public class BreakDemo
1:
2: import java.util.*;
3:
4: public class BreakDemo
5: {
6: public static void main(String[] args)
7: {
8: int itemNumber;
9: double amount, total;
10: Scanner keyboard = new Scanner(System.in);
11: System.out.println("You may buy ten items, but");
12: System.out.println("the total price must not exceed $100.");
13: total = 0;
14: for (itemNumber = 1; itemNumber <= 10; itemNumber++)
15: {
16: System.out.print("Enter cost of item #"
17: + itemNumber + ": $");
18: amount = keyboard.nextDouble( );
19: total = total + amount;
20: if (total >= 100)
21: {
22: System.out.println("You spent all your money.");
23: break;
24: }
25: System.out.println("Your total so far is $" + total);
26: System.out.println("You may purchase up to "
27: + (10 - itemNumber) + " more items.");
28: }
29: System.out.println("You spent $" + total);
30: }
31: }
32:
33: