
Write a program that prompts the user to enter the number of students and each studentâ??s name and score, and finally displays the name of the students with the highest score.

import java.util.*;
class ShowData {
String name;
int score;
ShowData(String name,int score){
this.name=name;
this.score=score;
}
public void setName(String name){
this.name = name;
}
public String getName() {
return name;
}
public void setScore(int score) {
this.score = score;
}
public int getScore(){
return score;
}
}
public class ArrayListEx{
public static void main(String[] args){
int max = Integer.MIN_VALUE;
Scanner input=new Scanner(System.in);
ArrayList<ShowData> list=new ArrayList<ShowData>();
for(int i=0;i<5;i++){
System.out.print("Enter name: ");
String name=input.next();
System.out.print("Enter Score: ");
int score=input.nextInt();
if (score > max) {
max = score;
}
list.add(new ShowData(name,score));
}
System.out.println("Students getting highest marks: ");
for(ShowData data: list){
if(data.getScore()==max){
System.out.println(data.getName()+"\t "+data.getScore());
}
}
}
}
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.