Advertisement
veronikaaa86

05. Account Balance

Apr 3rd, 2021
222
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.70 KB | None | 0 0
  1. package whileLoops;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class P05AccountBalance {
  6. public static void main(String[] args) {
  7. Scanner scanner = new Scanner(System.in);
  8.  
  9. String input = scanner.nextLine();
  10.  
  11. double sum = 0;
  12. while (!input.equals("NoMoreMoney")){
  13. double currentMoney = Double.parseDouble(input);
  14.  
  15. if (currentMoney < 0) {
  16. System.out.println("Invalid operation!");
  17. break;
  18. }
  19.  
  20. sum += currentMoney;
  21.  
  22. System.out.printf("Increase: %.2f%n", currentMoney);
  23.  
  24. input = scanner.nextLine();
  25. }
  26.  
  27. System.out.printf("Total: %.2f", sum);
  28. }
  29. }
  30.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement