stoyanoff

AccountBalance_05

Jul 6th, 2020
952
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.78 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class AccountBalance_05 {
  4.     public static void main(String[] args) {
  5.         Scanner myScan = new Scanner(System.in);
  6.  
  7.         double balance = 0;
  8.         boolean isValid = false;
  9.         while (!isValid) {
  10.  
  11.             String input = myScan.nextLine();
  12.             if (input.equals("NoMoreMoney")) {
  13.                 break;
  14.             }
  15.             double addBalance = Double.parseDouble(input);
  16.             if (addBalance <= 0) {
  17.                 System.out.println("Invalid operation!");
  18.                 isValid = true;
  19.             } else {
  20.                 System.out.printf("Increase: %.2f%n", addBalance);
  21.                 balance += addBalance;
  22.             }
  23.  
  24.  
  25.         }
  26.         System.out.printf("Total: %.2f", balance);
  27.     }
  28. }
Advertisement
Add Comment
Please, Sign In to add comment