Beginner JAVA4: Enter student information from the keyboard (name and score only) and output

Source: Internet
Author: User


//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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.