Advertisement
Helena12

AccountBalance

Nov 4th, 2018
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.61 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 depositNumber = Integer.parseInt(scanner.nextLine());   // Броят депозити, които ще се направят!
  8.         int counter = 1;                                            // Брояч на депозитите
  9.         double depositAmount = 0;                                   // Общата стойност на всички, направени депозити
  10.  
  11.  
  12.         while (counter <= depositNumber) {                      
  13.             double income = Double.parseDouble(scanner.nextLine()); // Стойността на направения депозит
  14.  
  15.             if (income < 0) {
  16.                 System.out.println("Invalid operation!");
  17.                 break;
  18.             } else {
  19.                 depositAmount += income;                           // Общата стойност се увеличава със всеки следващ направен депозит
  20.                 System.out.printf("Increase: %.2f\n", income);
  21.             }
  22.             counter++;                                             // Броячът отброява всеки депозит, доката достигне общият брой,
  23.         }                                                          // който трябва да бъде направен
  24.         System.out.printf("Total: %.2f", depositAmount);           // Отшечатваме общата стойност на депозитите
  25.     }
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement