平均数

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import java.util.Scanner;
public class stu {
    public static void main(String[] arge){
        System.out.print("请输入班级人数:");
       Scanner sca=new Scanner(System.in);//创建扫描对象,获取键盘上输入
        Scanner scanner=new Scanner(System.in);
        int num=scanner.nextInt();
        int i=0;
        int sum=0;
        while(i<num){
            System.out.print("请输入分数");
            Scanner scanner1=new Scanner(System.in);//创建扫描对象,获取键盘上输入
            int score=scanner.nextInt();
            sum=sum+score;
            i++;
        }
        double avg=sum/num;
        System.out.print("平均数为"+avg);
       // String str=sca.next();//从键盘上输入的对象转换为字符串
        // int a=sca.nextInt();//键盘上输入的对象转换成int
        //System.out.print(str);
        //System.out.print(a);
    }
}

 

posted @   逐梦武威  阅读(131)  评论(0编辑  收藏  举报
努力加载评论中...
点击右上角即可分享
微信分享提示