Beginner Java4: Enter student information (name and score only) on the keyboard and output it.
// Enter the student information (name and score only) on the keyboard and output it. Public class StuInformation {// StuScore may be more appropriate for naming String name; double score;} import java. util. contents;
public class TextStuInformation {
Public static void main (String [] args ){
Pipeline SC = new pipeline (System. in );
Int I = 0, j = 0;
// Information Input
System. out. print ("Enter the number of students you want to enter :");
Int num = SC. nextInt ();
StuInformation Stu [] = new StuInformation [num];
For (I = 0; I <Stu. length; I ++ ){
Stu [I] = new StuInformation ();
System. out. print ("Enter the" + (I + 1) + "Student name :");
Stu [I]. name = SC. next ();
System. out. print ("Enter the" + (I + 1) + "Student Score :");
Stu [I]. score = SC. nextDouble ();
}
// Information output
System. out. println ("\ t name \ t score ");
For (StuInformation stuInformation: Stu ){
System. out. println ("\ t" + stuInformation. name + "\ t" + stuInformation. score );
}
Double max = 0, min = 0;
Int cont = 0;
// Judge the highest score
For (I = 0; I <Stu. length; I ++ ){
If (max <Stu [I]. score ){
Max = Stu [I]. score;
Cont = I; // name of the student whose highest score is recorded
}
}
System. out. println ("Maximum score:" + Stu [cont]. name + "," + max );
// Determine the score
Min = Stu [0]. score;
For (j = 0; j <Stu. length; j ++ ){
If (min> = Stu [j]. score ){
Min = Stu [j]. score;
Cont = j; // name of the student whose lowest score is recorded
}
}
System. out. println ("min:" + Stu [cont]. name + "," + min );
SC. close ();
}
}
Result preview:
A_zhi
2016.08.18.22.00