重点是获取键盘输入的值
Scanner scanner = new Scanner(System.in);
int sum=scanner.nextint();
下面贴出完整代码
public class Average {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
int sum = 0;
int aver = 0;
Scanner scanner = new Scanner(System.in);
for (int i = 1; i < 4; i++) {
System.out.print("请输入第" + i + "学生的成绩:");
sum += scanner.nextInt();
aver = sum / i;
}
System.out.println("成绩和是" + sum);
System.out.println("平均成绩是" + aver);
}
}