Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class AccountBalance {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- int depositNumber = Integer.parseInt(scanner.nextLine()); // Броят депозити, които ще се направят!
- int counter = 1; // Брояч на депозитите
- double depositAmount = 0; // Общата стойност на всички, направени депозити
- while (counter <= depositNumber) {
- double income = Double.parseDouble(scanner.nextLine()); // Стойността на направения депозит
- if (income < 0) {
- System.out.println("Invalid operation!");
- break;
- } else {
- depositAmount += income; // Общата стойност се увеличава със всеки следващ направен депозит
- System.out.printf("Increase: %.2f\n", income);
- }
- counter++; // Броячът отброява всеки депозит, доката достигне общият брой,
- } // който трябва да бъде направен
- System.out.printf("Total: %.2f", depositAmount); // Отшечатваме общата стойност на депозитите
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement