Advertisement
Rayk

Untitled

Apr 16th, 2020
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.21 KB | None | 0 0
  1. package com.company;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class Main {
  6. public static void main(String[] args) {
  7. Scanner sc = new Scanner(System.in);
  8. int months = sc.nextInt();
  9. double waterBill = 20;
  10. double internetBill = 15;
  11. double otherBills = 0;
  12. double waterBillCnt = 0;
  13. double internetBillCnt = 0;
  14. double electricityBillCnt = 0;
  15. double otherBillsCnt = 0;
  16. for (int i = 1; i <= months; i++) {
  17. double electricityBill = sc.nextDouble();
  18. electricityBillCnt += electricityBill;
  19. waterBillCnt += waterBill;
  20. internetBillCnt += internetBill;
  21. otherBills = (electricityBill + waterBill + internetBill) * 1.2;
  22. otherBillsCnt += otherBills;
  23. }
  24. double avg = (electricityBillCnt + waterBillCnt + internetBillCnt + otherBillsCnt) / months;
  25. System.out.printf("Electricity: %.2f $\n", electricityBillCnt);
  26. System.out.printf("Water: %.2f $\n", waterBillCnt);
  27. System.out.printf("Internet: %.2f $\n", internetBillCnt);
  28. System.out.printf("Other: %.2f $\n", otherBillsCnt);
  29. System.out.printf("Average: %.2f $\n", avg);
  30. }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement