Advertisement
veronikaaa86

05. Account Balance

Jun 10th, 2023
865
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.69 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 amount = Double.parseDouble(input);
  14.  
  15.             if (amount < 0) {
  16.                 System.out.println("Invalid operation!");
  17.                 break;
  18.             }
  19.  
  20.             sum = sum + amount;
  21.  
  22.             System.out.printf("Increase: %.2f%n", amount);
  23.  
  24.             input = scanner.nextLine();
  25.         }
  26.  
  27.         System.out.printf("Total: %.2f%n", sum);
  28.     }
  29. }
  30.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement