Advertisement
veronikaaa86

05. Account Balance

Oct 30th, 2021
467
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.73 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(); //5.51 NoMoreMoney
  10.  
  11. double sum = 0;
  12. while (!input.equals("NoMoreMoney")) {
  13. double currentAmount = Double.parseDouble(input);
  14.  
  15. if (currentAmount < 0) {
  16. System.out.println("Invalid operation!");
  17. break;
  18. }
  19.  
  20. sum = sum + currentAmount;
  21. System.out.printf("Increase: %.2f%n", currentAmount);
  22.  
  23. input = scanner.nextLine();
  24. }
  25.  
  26. System.out.printf("Total: %.2f", sum);
  27. }
  28. }
  29.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement