Advertisement
psi_mmobile

Untitled

May 15th, 2022
848
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.16 KB | None | 0 0
  1.  //6.   Месечни разходи
  2. public class MyClass {
  3.     public static void main(String args[]) {
  4.        java.util.Scanner scanner = new java.util.Scanner(System.in);
  5.        int months = scanner.nextInt();
  6.        double electricityBill = 0.0;
  7.        
  8.        double electricityToPay = 0.0;
  9.        double waterToPay = 0.0;
  10.        double internetToPay = 0.0;
  11.        double otherExpensesToPay = 0.0;
  12.        
  13.        for (int i = 1; i <= months; i++) {
  14.            electricityBill = scanner.nextDouble();
  15.            electricityToPay += electricityBill;
  16.            waterToPay += 20;
  17.            internetToPay += 15;
  18.            otherExpensesToPay += (electricityBill + 20 + 15) * 1.2;
  19.        }
  20.        double averageMoneySpentPerMonth = (electricityToPay + waterToPay + internetToPay + otherExpensesToPay) / months;
  21.        
  22.        System.out.printf("Electricity: %.2f lv\n", electricityToPay);
  23.        System.out.printf("Water: %.2f lv\n", waterToPay);
  24.        System.out.printf("Internet: %.2f lv\n", internetToPay);
  25.        System.out.printf("Other: %.2f lv\n", otherExpensesToPay);
  26.        System.out.printf("Average: %.2f lv", averageMoneySpentPerMonth);
  27.     }
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement