Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 1

Scanner scanner = new Scanner(System.

in);
int noOfMonths = scanner.nextInt();
double billElectricity = 0;
double billWater=0;
double billInternet=0;
double billOther=0;
double billTotal=0;
double averageOfAll=0;

for (int i = 0; i <noOfMonths ; i++) {


double electricity=scanner.nextDouble();
double water=20;
double internet=15;
double other= electricity+water+internet+20/100;

billElectricity=billElectricity+electricity;
billWater=billWater+water;
billInternet=billInternet+internet;
billOther=billOther+other;
double average=billElectricity+billWater+billInternet+billOther;
billTotal=billTotal+average;
averageOfAll=billTotal/noOfMonths;

System.out.printf("Electricity: %.2f $\n",billElectricity);


System.out.printf("Water: %.2f $\n",billWater);
System.out.printf("Internet: %.2f $\n",billInternet);
System.out.printf("Other: %.2f $\n",billOther);
System.out.printf("Average: %.2f $",averageOfAll);

You might also like