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); 

} 

}
}

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.

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);
} 

}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.