I have to find the highest scoring student and the lowest scoring student from the given user input.but i only get the highest scoring student and can't get the lowest scoring student from it.
public class Student{
public String name;
public String id;
public int score;
public static int n;
public Student(String initName,String initID,int initScore){
initName=name;
initID=id;
initScore=score;
}
public Student (){
}
public static void main(String[] args) {
System.out.println("Enter the number of students:");
Scanner s1=new Scanner(System.in);
Student.n=Integer.parseInt(s1.nextLine().trim());
System.out.println("Enter the student name,id and score.");
Scanner s2=new Scanner(System.in);
Student st1=new Student();
Student min=new Student(" "," ",100);
Student max=new Student(" "," ",0);
for(int i=0;i<Student.n;i++){
st1.name=s2.next();
st1.id=s2.next();
st1.score=s2.nextInt();
if(max.score<st1.score){
max.score=st1.score;
max.name=st1.name;
max.id=st1.id;
}
if(min.score>st1.score){
min.name=st1.name;
min.score=st1.score;
min.id=st1.id;
}
}
System.out.println("the highest scoring student: "+max.name);
System.out.println("the lowest scoring student: "+min.name);
}
}