程序流程控制

package yw;
import java.util.Scanner;//调用系统函数Scanner
public class StudentScore  {//创建类StudentScore
public static void main(String[] args) 
        {
            // TODO Auto-generated method stub
            int m=5, i,j=0,g,sum=0,max,min=101;//定义变量
            int score[]=new int[m];//定义数组用于存储学生成绩
            Scanner sc=new Scanner(System.in);//实例化
            for(i=0;i<m;i++) //通过for循环从键盘多次输入成绩
            {
                System.out.println("请输入第"+(i+1)+"的位同学的成绩:");
                score[i]=sc.nextInt();//使用数组score接受存储学生成绩
           if(score[(i)]>0&&score[(i)]<=100) //通过if语句判断输入成绩是否有效。
                {
                    System.out.println("输入第"+(i+1)+"学生的成绩有效");
                    g=score[(i)]/10;
                    switch(g) //通过switch语句判断成绩的等级
                    {
                            case 10:System.out.println("第"+(i+1)+"学生的成绩等级为:A");break;
                            case 9:System.out.println("第"+(i+1)+"学生的成绩等级为:A");break;
                            case 8:System.out.println("第"+(i+1)+"学生的成绩等级为:B");break;
                            case 7:System.out.println("第"+(i+1)+"学生的成绩等级为:C");break;
                            case 6:System.out.println("第"+(i+1)+"学生的成绩等级为:D");break;
                            default:System.out.println("第"+(i+1)+"学生的成绩等级为:E");break;
                    }
                }
              else
            {
                System.out.println("输入第"+(i+1)+"学生的成绩无效");
                System.out.println("");
            }
                System.out.println("第"+(i+1)+"位学生的成绩:"+score[i]);
            }

            for(i=0;i<m;i++) //通过for语句输出每位学生成绩
            {
                System.out.println("第"+(i+1)+"位学生的成绩:"+score[i]);
            }

            while(j<m)//通过while语句获得m位学生的总成绩
            {
            sum=sum+score[j];
            j=j+1;
            }
            max=score[0];
            for(i=0;i<m;i++)//通过for语句获得这m位学生的最高成绩
            {
                if(score[i]〉max)
                max=score[i];
            }
            for(i=0;i<m;i++)//通过for语句获得这m位学生的最低成绩
            {
                if (score[i]<min)
                min=score[i];
            }
            System.out.println("这"+i+"位学生的成绩最高成绩为:"+max);
            System.out.println("这"+i+"位学生的成绩最低成绩为:"+min);
            System.out.println("这"+i+"位学生的总成绩为:"+sum);
            }

    }

运行结果如下:
这里写图片描述
一,本章实训的知识点:
1,if-else语句的使用,switch语句使用
2,for循环语句的使用,while循环语句和do-while循环语句的使用及跳转语句break,continue,return语句的使用。
3,多种控制语句的嵌套,如:题中for循环语句和if-else语句的嵌套,得到5位学生的最高成绩,最低成绩,总成绩。

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值