I am doing a class in Computer Programming and right now we're using Arrays. My objective is to do the following:
~ Prompt users for how many math tests they have written this year. ~ Asks the users their score on each of these math tests. ~ Place each score in an array. ~ Sort the array and give their math scores from least to greatest. ~ Calculate an average of the math scores.
My problem occurs when it just only keeps the scores at 0 and later wont recognize the testGrade int variable so it won't average them.
Here is my full code as of right now:
public static void main(String... args) throws Exception
{
for (int i = 0;i < testResults.length; i++)
{
System.out.print("Thank you, now please enter your grade on each test: ");
int testGrades = k.nextInt();
}
System.out.print("The original sequence is: \n ");
for (int i = 0;i < testResults.length; i++)
{
System.out.print(testResults [i] + ", ");
}
System.out.println();
SortEm(testResults);
System.out.print("The new sequence is : \n ");
for (int i=0; i < testResults.length; i++)
{
System.out.print (testResults[i] + ", ");
}
System.out.println();
for (int i = 0;i < testResults.length; i++)
{
System.out.println("The average of all your tests is " + (testGrades / testNum));
}
}
private static void SortEm (int [] ar)
{
int temp;
for (int i = ar.length - 1; i > 0; i--)
{
for (int j = 0; j < i; j++)
{
if (ar[j] > ar[j + 1])
{
temp = ar[j];
ar[j] = ar[j + 1];
ar[j+1] = temp;
}
}
}
}
I would really appreciate some insight on what's going on and how to fix it. Thank you all in advance :)
My Errors after answer: 6 errors found: File: C:\Users\herhstudent\Desktop\gg.java [line: 1] Error: Syntax error on tokens, delete these tokens File: C:\Users\herhstudent\Desktop\gg.java [line: 3] Error: Syntax error on token "void", @ expected File: C:\Users\herhstudent\Desktop\gg.java [line: 3] Error: Syntax error on token "...", . expected File: C:\Users\herhstudent\Desktop\gg.java [line: 3] Error: Syntax error on token "throws", interface expected File: C:\Users\herhstudent\Desktop\gg.java [line: 6] Error: Syntax error on token ";", { expected after this token File: C:\Users\herhstudent\Desktop\gg.java [line: 44] Error: Syntax error, insert "}" to complete InterfaceBody