Advertisement
veronikaaa86

05. Account Balance

Jul 30th, 2022
1,256
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 inputLine = scanner.nextLine();
  10.  
  11.         double sum = 0;
  12.         while (!inputLine.equals("NoMoreMoney")) {
  13.             double amount = Double.parseDouble(inputLine);
  14.             if (amount < 0) {
  15.                 System.out.println("Invalid operation!");
  16.                 break;
  17.             }
  18.  
  19.             sum += amount;
  20.             System.out.printf("Increase: %.2f%n", amount);
  21.             inputLine = scanner.nextLine();
  22.         }
  23.  
  24.         System.out.printf("Total: %.2f%n", sum);
  25.     }
  26. }
  27.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement