Blog / 阅读

Java中while循环用法

by admin on 2014-04-03 10:46:30 in ,



编程:录入班级人数、学员成绩全班平均分;


[java] view plaincopy
Scanner s=new Scanner(System.in);  
        System.out.println("请输入您班上的人数:");  
        int people=s.nextInt();  
        int i=1;  
        int sum=0;  
        while(i<=people){  
            System.out.println("请输入学号"+i+"的成绩!");  
            int score=s.nextInt();  
            while(score<0||score>100){  
                System.out.println("您输入的分数有误,请重新输入:");  
                score=s.nextInt();  
            }  
            sum=sum+score;  
            i++;  
        }  
        int avg=sum/people;  
        System.out.println("全班平均成绩为:"+avg);  


while中还可以嵌入while,不满足条件时就一直循环。


写评论

相关文章

上一篇:php解析doc格式word文件的另一种方法

下一篇:DES加密算法详解- -

评论

写评论

* 必填.

分享

栏目

赞助商


热门文章

Tag 云