Advertisement
desislava_topuzakova

05. Account Balance

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