Advertisement
Guest User

AccountBalance

a guest
Apr 15th, 2020
196
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.66 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.  
  7.         int n = Integer.parseInt(scanner.nextLine());
  8.         int i = 0;
  9.  
  10.         double total = 0.0;
  11.         while (i < n) {
  12.             double number = Double.parseDouble(scanner.nextLine());
  13.             if (number < 0) {
  14.                 System.out.println("Invalid operation!");
  15.                 break;
  16.             }
  17.  
  18.             System.out.printf("Increase: %.2f%n", number);
  19.             total += number;
  20.             i++;
  21.         }
  22.  
  23.         System.out.printf("Total: %.2f", total);
  24.     }
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement