日期:2014-05-20 浏览次数:20637 次
package com.itcast.itwork;
import java.util.Scanner;
public class StudentXinXi {
/**
* @param args
*/
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.println("请输入学生人数:");
int index = input.nextInt();
Xue [] stu = new Xue[index];
int scors = 0;
for(int i=0; i<index; i++) {
System.out.println("请输入学生姓名:");
String s = input.next();
stu[i].setName(s);
System.out.println("请输入学生成绩");
int in = input.nextInt();
stu[i].setScore(in);
}
for(int i=0; i<index; i++) {
System.out.println("学生姓名:" + stu[i].getName() + "学生成绩:" + stu[i].getScore());
scors += stu[i].getScore();
}
System.out.println("总成绩为:" + scors);
System.out.println("平均成绩为:" + (scors/index));
}
}
class Xue {
private String name;
private int score;
public Xue(String name, int score) {
this.name = name;
this.score = score;
}
public Xue() {}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getScore() {
return score;
}
public void setScore(int score) {
this.score = score;
}
}