統計一個班級所有學生績點
鍵盤輸入若干學生資訊,包括姓名,年齡,性別,數學,語文,英語成績
統計平均績點前三名學生,并輸出前三名學生基本資訊和成績
績點規則:100 5。90及以上,4。80及以上,3。70及以上,2。60及以上,1。其他0
目前只寫道了鍵盤輸入若干學生資訊,包括姓名,年齡,性別,數學,語文,英語成績 用的是String student1[] = new String[6]; 求大佬看下
package com.company;
import java.awt.*;
import java.util.Scanner;
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);
// 接收輸入的數字,把數字存入陣列
for (int i = 0; i <student.length; i++)
{
// 每次輸出輸入提示
System.out.print("請輸入學生資訊");
// 對應的索引的數值 = 接收到的數值
student[i] =sc.nextLine();
System.out.print("請輸入學生年齡");
// 對應的索引的數值 = 接收到的數值
student[i+1] = sc.nextLine();
System.out.print("請輸入學生性別");
// 對應的索引的數值 = 接收到的數值
student[i+2] = sc.nextLine();
System.out.print("請輸入學生數學成績");
// 對應的索引的數值 = 接收到的數值
student[i+3] = sc.nextLine();
System.out.print("請輸入學生英語成績");
// 對應的索引的數值 = 接收到的數值
student[i+4] =sc.nextLine();
System.out.print("請輸入學生語文成績");
// 對應的索引的數值 = 接收到的數值
student[i+5] = sc.nextLine();
System.out.println();
break;
}
for (int i = 0; i < student.length; i++) {
System.out.print(student[i]+",");
}
System.out.println();
for (int i = 0; i <student1.length; i++)
{
// 每次輸出輸入提示
System.out.print("請輸入學生資訊");
// 對應的索引的數值 = 接收到的數值
student1[i] =sc.nextLine();
System.out.print("請輸入學生年齡");
// 對應的索引的數值 = 接收到的數值
student1[i+1] = sc.nextLine();
System.out.print("請輸入學生性別");
// 對應的索引的數值 = 接收到的數值
student1[i+2] = sc.nextLine();
System.out.print("請輸入學生數學成績");
// 對應的索引的數值 = 接收到的數值
student1[i+3] = sc.nextLine();
System.out.print("請輸入學生英語成績");
// 對應的索引的數值 = 接收到的數值
student1[i+4] =sc.nextLine();
System.out.print("請輸入學生語文成績");
// 對應的索引的數值 = 接收到的數值
student1[i+5] = sc.nextLine();
System.out.println();
break;
}
for (int i = 0; i < student1.length; i++) {
System.out.print(student1[i]+",");
}
}
}
uj5u.com熱心網友回復:
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;
public class Test {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("請輸入要輸入的學生個數:");
int nextInt = sc.nextInt();
List<Student> students = new ArrayList<Student>();
Student stu = null;
for (int i = 0; i < nextInt; i++) {
stu = new Student();
System.out.println("請輸入第 " + (i + 1) + "學生姓名");
stu.name = sc.next();
System.out.println("請輸入第 " + (i + 1) + "學生年齡");
stu.age = sc.nextInt();
System.out.println("請輸入第 " + (i + 1) + "學生性別");
stu.sex = sc.next();
System.out.println("請輸入第 " + (i + 1) + "學生數學成績");
stu.mathematics = sc.nextDouble();
System.out.println("請輸入第 " + (i + 1) + "學生英語成績");
stu.english = sc.nextDouble();
System.out.println("請輸入第 " + (i + 1) + "學生語文成績");
stu.chinese = sc.nextDouble();
students.add(stu);
}
Collections.sort(students);
System.out.println(students);
}
}
class Student implements Comparable<Student>{
// 姓名,年齡,性別,數學,語文,英語成績
String name;
int age;
String sex;
double mathematics;
double chinese;
double english;
private double getAvg(){
return (mathematics + chinese + english) / 3;
}
@Override
public int compareTo(Student o) {
return (int)(this.getAvg() - o.getAvg());
}
@Override
public String toString() {
return name + "--" + this.getAvg();
}
}
uj5u.com熱心網友回復:
大佬績效點 寫了嗎???轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/209905.html
標籤:Java相關
