Advertisement
SvetlanPetrova

Account Balance SoftUni

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