1) Initialize all elements of the array to -1. (dont know what that means)
2) Modify a single score by prompting the user for a new score and the index in which to store it. Do not allow the user to access beyond the bounds of the array.
3) Print all 10 scores and WITH THEIR ASSOCIATED LETTER GRADE sequentially to the screen using a loop.
4) Print a single score by prompting the user to input an index to display. Do not allow the user to access beyond the bounds of the array.
5) When printing the lowest score-it cant be -1
I've been working on this code for hours and your help would be greatly appreciated!
import java.util.Scanner;
public class TestScores
{
public static void main (String[] args)
{
Scanner keyboard = new Scanner(System.in);
int scores[] = new int[10];
for ( int i = 0; i < scores.length; i++ )
{
System.out.println("Enter Score " + (i+1) + ": ");
scores[i] = keyboard.nextInt();
}
// print out exam scores
System.out.println ("Exam Scores: ");
for (int i = 0; i < scores.length; i++ )
System.out.print(scores[i] + " ");
System.out.println();
// compute average
double average = 0;
for (int i = 0; i < scores.length; i++ )
average = average + scores[i];
average = average / scores.length;
System.out.printf ("Average Score is: %-10.3f\n", + average);
// find highest score
int highest = scores[0];
for (int i = 1; i < scores.length; i++ )
{
if (highest < scores[i] )
highest = scores[i];
}
System.out.println("Highest Score is: " + highest);
// find lowest score
int lowest = scores[0];
for (int i = 1; i > scores.length; i++ )
{
if (lowest > scores[i] )
lowest = scores[i];
}
System.out.println("Lowest Score is: " + lowest);
}
}

New Topic/Question
Reply




MultiQuote





|