1) You have an extra curly brace here:
}
for(int x = 0; x < arynums; x++){
calorieaverage = (calorieaverage + arynums[x]);
}
Remove the top }.
2) At the same for loop, change arynums to arnums.length.
3) At this loop:
for(int x = 0; x < aryMonth.length; x++)
{
System.out.println("" + arymonth[x] + " " + arynums[x]);
}
Change arymonth[x] to aryMonth[x].
4) System.out.println("The total for the year is >", calorieaverage);
I don't think this is allowed. Change it to System.out.println("The total for the year is >" + calorieaverage); I believe java will already convert calorieaverage to the equivalent string form.
Do the same for the other System.out.println.
edit: You should also declare monthlyaverage as a double or float instead of an integer, because the average isn't guaranteed to be an integer. In this case, you should also change this line:
monthlyaverage = calorieaverage/12 to monthlyaverage = calorieaverage/12.0
The final program should then be:
Code
import java.util.Scanner; //util/scannerclass
import java.io.*; //needed for files
public class Lab4 {
public static void main(String[]args) throws FileNotFoundException {
int calorieaverage=0;
double monthlyaverage;
Scanner keyboard = new Scanner(System.in); //input new scanner
int[] arynums = { 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 4000, 2000};
String[] aryMonth = { "Jan", "Feb", "Mar", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
for(int x = 0; x < aryMonth.length; x++) {
System.out.println("" + aryMonth[x] + " " + arynums[x]);
}
for(int x = 0; x < arynums.length; x++) {
calorieaverage = (calorieaverage + arynums[x]);
}
monthlyaverage= calorieaverage/12.0;
System.out.println("The total for the year is >" + calorieaverage);
System.out.println("The average monthly total is >" + monthlyaverage);
}
}
This post was edited by INeedALife22 on Dec 19 2012 02:30am