Advertisement
veronikaaa86

05. Account Balance

Jun 4th, 2022
294
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.70 KB | None | 0 0
  1. package whileLoop;
  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. if (currentMoney < 0) {
  15. System.out.println("Invalid operation!");
  16. break;
  17. }
  18. System.out.printf("Increase: %.2f%n", currentMoney);
  19.  
  20. sum = sum + currentMoney;
  21.  
  22. input = scanner.nextLine();
  23. }
  24.  
  25. System.out.printf("Total: %.2f", sum);
  26. }
  27. }
  28.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement