在循环中使用continue语句

continue;//表示继续,当遇到continue语句时,则结束当次循环继续执行下一次循环  例子:

  

 1 class For09{
 2     public static void main(String[ ]args){
 3         //输入5个人Java学生的考试成绩,统计成绩在95分以上的人数
 4         Scanner input = new Scanner(System.in);
 5         int count = 0;    //表示统计95分以上的人数
 6         for(int i = 1 ; i <=5 ; i ++){
 7             System.out.print("请输入第"+ i +"个人的成绩:");
 8             double score = input.nextDouble();
 9             //判断,当前成绩score,如果在95分及以下则继续输入下一个人成绩
10             if(score <=95){
11                 continue;    //表示继续,当遇到continue语句时,则结束当次循环继续执行下一次循环
12             }
13             //统计95分以上的人数
14             count++;
15         }
16         System.out.println("在95分以上的成绩的人数有:"+ count);
17     }
18 }

 

posted @ 2019-04-13 11:44  Penphy  阅读(1230)  评论(0编辑  收藏  举报