Advertisement
Guest User

AccountBalance

a guest
Sep 16th, 2021
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.53 KB | None | 0 0
  1. String input = scanner.nextLine();
  2. double sum = 0.0;
  3.  
  4. while (!input.equals("NoMoreMoney")) {
  5. double currentNum = Double.parseDouble(input); // not (scanner.nextLine()) !!! ???
  6. if (currentNum < 0) {
  7. System.out.println("Invalid operation!");
  8. break;
  9. }
  10. System.out.printf("Increase: %.2f%n", currentNum);
  11. sum += currentNum;
  12.  
  13. input = scanner.nextLine();
  14. }
  15. System.out.printf("Total: %.2f", sum);
  16.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement