Keyboard input some student information, including name, age, gender, math, Chinese, English
Three students ahead of statistical grade point average, and output the top three students basic information and
Grade point rule: 100 5, living and above, more than 4 reached and 3; seven or more, other 2, 60 and above, 1, 0
Currently only writes the keyboard input number of student information, including name, age, gender, math, Chinese, English is the String student1 []=new String [6]. O bosses see
Pany package com.com;
import java.awt.*;
import java.util.Scanner;
The class Main {
Private static Object String;
Public static void main (String [] args)
{
String student []=new String [6].
String student1 []=new String [6].
Scanner sc=new Scanner(System.in);
//receive input Numbers, the Numbers in the array
For (int I=0; I & lt; Student. Length; I++)
{
//for each input output
System. The out. Print (" please enter the student information ");
//the corresponding index value=receive numerical
Student [I]=sc. NextLine ();
System. The out. Print (" please input the student age ");
//the corresponding index value=receive numerical
Student [I + 1)=sc. NextLine ();
System. The out. Print (" please enter the student gender ");
//the corresponding index value=receive numerical
Student [I + 2]=sc. NextLine ();
System. The out. Print (" please enter the student mathematics result ");
//the corresponding index value=receive numerical
Student [I + 3]=sc. NextLine ();
System. The out. Print (" please enter the student English ");
//the corresponding index value=receive numerical
Student [I + 4]=sc. NextLine ();
System. The out. Print (" please enter the students' Chinese achievement ");
//the corresponding index value=receive numerical
Student/I + 5=sc. NextLine ();
System.out.println();
break;
}
For (int I=0; I & lt; Student. Length; I++) {
System. The out. Print (student [I] + ", ");
}
System.out.println();
For (int I=0; I & lt; Student1. Length; I++)
{
//for each input output
System. The out. Print (" please enter the student information ");
//the corresponding index value=receive numerical
Student1 [I]=sc. NextLine ();
System. The out. Print (" please input the student age ");
//the corresponding index value=receive numerical
Student1 [I + 1)=sc. NextLine ();
System. The out. Print (" please enter the student gender ");
//the corresponding index value=receive numerical
Student1 [I + 2]=sc. NextLine ();
System. The out. Print (" please enter the student mathematics result ");
//the corresponding index value=receive numerical
Student1 [I + 3]=sc. NextLine ();
System. The out. Print (" please enter the student English ");
//the corresponding index value=receive numerical
Student1 [I + 4]=sc. NextLine ();
System. The out. Print (" please enter the students' Chinese achievement ");
//the corresponding index value=receive numerical
Student1] [I + 5=sc. NextLine ();
System.out.println();
break;
}
For (int I=0; I & lt; Student1. Length; I++) {
System. The out. Print (student1 [I] + ", ");
}
}
}
CodePudding user response:
import Java. Util. ArrayList;
Import the Java. Util. Collections;
Import the Java. Util. List;
import java.util.Scanner;
Public class Test {
Public static void main (String [] args) {
Scanner sc=new Scanner(System.in);
System. The out. Println (" please input the number of students to enter: ");
Int nextInt=sc. NextInt ();
ListStudents=new ArrayList (a);
Student stu=null;
For (int I=0; I & lt; NextInt; I++) {
Stu=new Student ();
System. Out. Println (" please enter the first "+ (I + 1) +" student's name ");
Stu. Name=sc. Next ();
System. The out. Println (" please enter the first "+ (I + 1) +" student age ");
Stu. Age=sc. NextInt ();
System. The out. Println (" please enter the first "+ (I + 1) +" student gender ");
Stu. Sex=sc. Next ();
System. The out. Println (" please enter the first "+ (I + 1) +" students' math scores ");
Stu. Mathematics=sc. NextDouble ();
System. The out. Println (" please enter the first "+ (I + 1) +" students English ");
Stu. English=sc. NextDouble ();
System. The out. Println (" please enter the first "+ (I + 1) +" students' Chinese achievement ");
Stu. Chinese=sc. NextDouble ();
Students. The add (stu);
}
The Collections. Sort (students);
System.out.println(students);
}
}
The class Student implements Comparable{
//the name, age, gender, mathematics, Chinese, English
String name;
int age;
String sex;
Double mathematics;
Double Chinese;
Double English;
Private double getAvg () {
Return (mathematics, Chinese and English)/3;
}
@ Override
Public int compareTo () Student o {
Return (int) (enclosing getAvg () - o.g etAvg ());
}
@ Override
Public String toString () {
Return the name + "--" + this. GetAvg ();
}
}
CodePudding user response:
Heavyweight performance point wrote???