0

Hi I am creating a program that needs to take 10 grades and give you the average, lowest, and highest grades. It needs to use arrays. Have I used arrays or used they correctly so far? Where do I need to put the grades in at? I have written part of the program but dont know what to do can anyone help?

public class Arrayofscores
{
public static void main(String args[])
{
int [] scores = new int[10];
int smallest, highest,total=0;
double average =0.0;
{
//lowest score
smallest = scores[0];

for (int i = 1; i <= scores.length-1;i++)
if (scores[i] < smallest)
smallest = scores[i];

System.out.println("The lowest score is : " + smallest);

//highest score
highest = scores[0];

for (int i = 1; i <= scores.length-1;i++)
if (scores[i] > highest)
highest = scores[i];

System.out.println("The highest score is : " + highest);

//average score
for (int i = 0; i<=scores.length-1;i++)
total = total + scores[i];

average = total/10.0;
System.out.println("The average score is : " + average); 

} 

}
}

Edited by peter_budo: Keep It Organized - Please use [code] tags and do not use generic thread title such as &quot;HELP ME&quot;

3
Contributors
2
Replies
3
Views
7 Years
Discussion Span
Last Post by vchandra
0

Lines 8 and 34 have unnecessary braces. There is no need for { or } in those locations. You should create a for-loop after declaring the array that prompts the user to enter an integer as the grade and then stores the integer in the array, and it should loop until the array has been filled.

-1
public class Arrayofscores
{
    public static void returnResult(int[] nums){
        double avg = 0;
        Arrays.sort(nums);
        System.out.println("Smallest Number is = "+nums[0]);
        System.out.println("Highest Number is = "+nums[nums.length-1]);
        for(int i=0; i<nums.length; i++)
            avg+= nums[i];
        avg = avg/nums.length;
        System.out.println("Average number is = "+avg);
    }

public static void main(String args[])
{
    int [] nums = {12,4,43,64,64,65,76,44,67,87,33,9};
    Arrayofscores.returnResult(nums);
} 

}

Edited by Reverend Jim: Fixed formatting

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.