public?class?Student?{
創(chuàng)新互聯公司長期為數千家客戶提供的網站建設服務,團隊從業(yè)經驗10年,關注不同地域、不同群體,并針對不同對象提供差異化的產品和服務;打造開放共贏平臺,與合作伙伴共同營造健康的互聯網生態(tài)環(huán)境。為清苑企業(yè)提供專業(yè)的網站制作、網站建設,清苑網站改版等技術服務。擁有10多年豐富建站經驗和眾多成功案例,為您定制開發(fā)。
private?int?kemu1,?kemu2,?kemu3,?kemu4,?kemu5;
public?int?getKemu1()?{
return?kemu1;
}
public?void?setKemu1(int?kemu1)?{
this.kemu1?=?kemu1;
}
public?int?getKemu2()?{
return?kemu2;
}
public?void?setKemu2(int?kemu2)?{
this.kemu2?=?kemu2;
}
public?int?getKemu3()?{
return?kemu3;
}
public?void?setKemu3(int?kemu3)?{
this.kemu3?=?kemu3;
}
public?int?getKemu4()?{
return?kemu4;
}
public?void?setKemu4(int?kemu4)?{
this.kemu4?=?kemu4;
}
public?int?getKemu5()?{
return?kemu5;
}
public?void?setKemu5(int?kemu5)?{
this.kemu5?=?kemu5;
}
}
上邊的是Student類
import?java.util.ArrayList;
import?java.util.Random;
public?class?Test?{
public?static?void?main(String[]?args)?{
ArrayListStudent?list?=?new?ArrayListStudent();
//?初始化成績
for?(int?n?=?0;?n??20;?n++)?{
Student?st?=?new?Student();
st.setKemu1(new?Random().nextInt(100));
st.setKemu2(new?Random().nextInt(100));
st.setKemu3(new?Random().nextInt(100));
st.setKemu4(new?Random().nextInt(100));
st.setKemu5(new?Random().nextInt(100));
list.add(st);
}
//?計算平均成績
int?avg?=?0;
for?(int?n?=?0;?n??20;?n++)?{
avg?+=?list.get(n).getKemu1();
avg?+=?list.get(n).getKemu2();
avg?+=?list.get(n).getKemu3();
avg?+=?list.get(n).getKemu4();
avg?+=?list.get(n).getKemu5();
}
double?avg2?=?avg?/?20;
System.out.println("全班平均成績"?+?avg2);
//?計算誰得獎
for?(int?n?=?0;?n??20;?n++)?{
double?avg3;
int?avg4?=?0;
avg4?+=?list.get(n).getKemu1();
avg4?+=?list.get(n).getKemu2();
avg4?+=?list.get(n).getKemu3();
avg4?+=?list.get(n).getKemu4();
avg4?+=?list.get(n).getKemu5();
avg3?=?avg4;
System.out.println((n?+?1)?+?"成績?yōu)??+?avg3);
if?(avg3??(avg2?*?1.2))?{
System.out.println((n?+?1)?+?"該生獲得1等將");
}
if?(avg3??(avg2?*?1.1))?{
System.out.println((n?+?1)?+?"該生獲得2等將");
}
}
}
}
好了 可以了
ArrayList是動態(tài)數組
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
public class GradeStatistic {
public static void main(String[] args) {
GradeStatistic gs = new GradeStatistic();
ListMark list = new ArrayListMark();
float sum = 0;
while(true){
Scanner sc = new Scanner(System.in);
System.out.print("Please input student name: ");
String name = sc.nextLine();
if(name.equals("end")){
break;
}
System.out.print("Please input student score: ");
float score = sc.nextFloat();
sum += score;
list.add(gs.new Mark(name, score));
}
float max = list.get(0).getScore();
float min = list.get(0).getScore();
for(Mark mark: list){
if(max mark.getScore()){
max = mark.getScore();
}
if(min mark.getScore()){
min = mark.getScore();
}
}
float average = sum / list.size();
System.out.println("Average is: " + average);
System.out.println("Max is: " + max);
System.out.println("Min is: " + min);
}
private class Mark{
private String name;
private float score;
public Mark(String name, float score){
this.name = name;
this.score = score;
}
public String getName() {
return name;
}
public float getScore() {
return score;
}
}
}
----------------------
Please input student name: Zhang san
Please input student score: 100
Please input student name: Li Si
Please input student score: 91
Please input student name: Ec
Please input student score: 35
Please input student name: ma qi
Please input student score: 67
Please input student name: end
Average is: 73.25
Max is: 100.0
Min is: 35.0
if (course = 90) {
System.out.println("A");
} else if (course = 80 course 90) {
System.out.println("B");
} else if (course = 70 course 80) {
System.out.println("C");
} else if (course = 60 course 70) {
System.out.println("D");
} else {
System.out.println("E");
}
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
public class Student {
/**
* 學生成績表
*/
private String name;//學生姓名
private double score;//學生成績
public Student(){}
public Student(String name,double score){
this.name=name;
this.score=score;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public double getScore() {
return score;
}
public void setScore(double score) {
this.score = score;
}
//主函數
public static void main(String[] args) {
ListStudent list=new ArrayListStudent();
Student[] stu=new Student[5];
//為學生對象賦值
for(int i=0;i5;i++){
stu[i]=new Student();
Scanner sc=new Scanner(System.in);
System.out.print("請輸入學生姓名:");
stu[i].setName(sc.next());
System.out.print("請輸入學生成績:");
stu[i].setScore(sc.nextDouble());
list.add(stu[i]);
}
//打印輸出學生成績表
System.out.println("姓名\t成績");
for(Student s:list){
System.out.println(s.getName()+"\t"+s.getScore());
}
}
}