编程,把百分制成绩转换成5级记分制,要求用switch语句.

2024-11-13 04:34:06
推荐回答(3个)
回答1:

具体方法与演示结果如图:

回答2:

#include "stdio.h"

void main()
{
int i,score;
char band;
for(i=0;i<5;i++)
{
printf("Input Score:");
scanf("%d",&score);
switch(score/10)
{
case 10:
case 9: band='A'; break;
case 8: band='B'; break;
case 7: band='C'; break;
case 6: band='D'; break;
default: band='E'; break;
}
printf("%d的等级为%c\n",score,band);
}
}

回答3:

Scanner sc = new Scanner(System.in);
System.out.print("请输入成绩:");
int score = sc.nextInt();
System.out.println();
String print;
switch (score/10) {
case 9:
print = "A";
break;
case 8:
print = "B";
break;
case 7:
print = "C";
break;
case 6:
print = "D";
break;

default:
print = "F";
break;
}
System.out.println(score+"等级为"+print);