Advertisement
myrdok123

05. Account Balance

Apr 6th, 2024
722
0
Never
2
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.76 KB | None | 0 0
  1. package WhileLoop;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class P05AccountBalance {
  6.  
  7.     public static void main(String[] args) {
  8.         Scanner scanner = new Scanner(System.in);
  9.  
  10.         String input = scanner.nextLine();
  11.  
  12.         double totalMoney = 0;
  13.  
  14.  
  15.  
  16.         while (!input.equals("NoMoreMoney")){
  17.  
  18.             double currentMoney = Double.parseDouble(input);
  19.  
  20.             if(currentMoney < 0){
  21.                 System.out.println("Invalid operation!");
  22.                 break;
  23.             }else {
  24.                 totalMoney += currentMoney;
  25.                 System.out.printf("Increase: %.2f%n", currentMoney);
  26.             }
  27.  
  28.             input = scanner.nextLine();
  29.  
  30.         }
  31.  
  32.         System.out.printf("Total: %.2f", totalMoney);
  33.  
  34.  
  35.     }
  36. }
  37.  
Advertisement
Comments
Add Comment
Please, Sign In to add comment
Advertisement