Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package PBMoreExercisesForLoop;
- import java.util.Scanner;
- public class Bills {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- int months = Integer.parseInt(scanner.nextLine());
- double totalElectricity = 0;
- double water = 20;
- double internet = 15;
- double allOthers = 0;
- for (int i = 1; i <= months ; i++) {
- double electricity = Double.parseDouble(scanner.nextLine());
- totalElectricity = totalElectricity + electricity;
- double others = (electricity + water + internet) + (electricity + water + internet) * 20 / 100;
- allOthers = allOthers + others;
- }
- water = water * months;
- internet = internet * months;
- double costs = totalElectricity + water + internet + allOthers;
- double averageCosts = costs / months;
- System.out.printf("Electricity: %.2f lv%n", totalElectricity);
- System.out.printf("Water: %.2f lv%n", water);
- System.out.printf("Internet: %.2f lv%n", internet);
- System.out.printf("Other: %.2f lv%n", allOthers);
- System.out.printf("Average: %.2f lv", averageCosts);
- }
- }
Add Comment
Please, Sign In to add comment