//Enter student information (name and score only) from the keyboard and output. public class Stuinformation {//here named with Stuscore may be more appropriate String name; double score; }import Java.util.Scanner;
public class Textstuinformation {
Public static void Main (string[] args) {
Scanner sc = new Scanner (system.in);
int i = 0, j = 0;
//Information entry
System.out.print ("Please enter the number of students you want to input:");
int num = Sc.nextint ();
stuinformation stu[] = new Stuinformation[num];
For (i = 0; i < stu.length; i++) {
Stu[i] = new Stuinformation ();
System.out.print ("Please enter" + (i + 1) + "Student's name:");
stu[i].name = Sc.next ();
System.out.print ("Please enter" + (i + 1) + "Student's score:");
Stu[i].score = sc.nextdouble ();
}
//Information output
System.out.println ("\ t name \ t grade");
For (stuinformation stuinformation:stu) {
System.out.println ("\ t" + Stuinformation.name + "\ T" + stuinformation.score);
}
Double max = 0, min = 0;
int cont = 0;
//Judging the highest score
For (i = 0; i < stu.length; i++) {
if (Max < Stu[i].score) {
max = Stu[i].score;
cont = i;//The name of the classmate used to record the highest score
}
}
System.out.println ("Highest score is:" + Stu[cont].name + "," + max);
//Judging the lowest score
min = stu[0].score;
For (j = 0; J < Stu.length; J + +) {
if (min >= stu[j].score) {
min = stu[j].score;
cont = j;//The name of the classmate used to record the lowest score
}
}
System.out.println ("The lowest score is:" + Stu[cont].name + "," + min);
sc.close ();
}
}
Results preview:
A_zhi
2016.08.18.22.00
Beginner JAVA4: Enter student information from the keyboard (name and score only) and output