Advertisement
Spocoman

05. Account Balance

Aug 28th, 2024 (edited)
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.64 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class AccountBalance {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.         String input = scanner.nextLine();
  7.         double sum = 0;
  8.  
  9.         while (!input.equals("NoMoreMoney")) {
  10.             double money = Double.parseDouble(input);
  11.             if (money < 0) {
  12.                 System.out.println("Invalid operation!");
  13.                 break;
  14.             }
  15.             sum += money;
  16.             System.out.printf("Increase: %.2f\n", money);
  17.             input = scanner.nextLine();
  18.         }
  19.  
  20.         System.out.printf("Total: %.2f\n", sum);
  21.     }
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement