I need help writing a simple and easy to understand program
I need help writing a simple and easy to understand program in Java. Here is the exercise I need a program for:
Write a program that prompts the user to enter the number of students and each student\'s name and score, and finally displays the student with the highest score and the student with the second-highest score.
Solution
class Score
{
public static void main(String args[])
{ int maxIndex, seMaxIndex;
Scanner s = new Scanner(System.in);
System.out.println(\"Please enter number of students\");
n = s.nextInt();
String[] name = new String[n];
String[] score = new String[n];
for(int i=0;i<n;i++);
{
System.out.println(\"Please enter name\");
name[i] = s.nextLine();
System.out.println(\"Please enter the score\");
score[i] = s.nextInt();
}
int max = score[0];
int seMax = score[1];
for(int i=2;i<n;i++)
{
if(score[i]>max)
{ if(max>seMax)
seMax = max;
max = score[i];
maxIndex = i;
}
else if(score[i]>seMax)
{seMax = score[i];
seMaxIndex = i;
}
}
System.out.println(\"The student with hightest score is\" + name[maxIndex]);
System.out.println(\"The student with second hightest score is\" + name[seMaxIndex]);
}
}
