这是源程序
package forDemo;
import java.util.Scanner;
public class forDemo {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
int score;
int sum=0;
double avg =0.0;
Scanner input =new Scanner(System.in);
System.out.println("请输入姓名:···");
String name =input.next();
for (int i = 0; i < 5; i++) {
System.out.println("请输入5门功课的成绩"+(i+1)+"门课的成绩");
score = input.nextInt();
sum = sum + score;
}
avg = sum/5;
System.out.println(name +"的平均分是:"+avg);
}
}
|
|