2句实现.设计一个程序,将从键盘上输入的百分制成绩转换成对应的五分制成绩并输出。
2句实现.设计一个程序,将从键盘上输入的百分制成绩转换成对应的五分制成绩并输出。90分以上为A,80-89分为B,70-79分为C,60-69分为D,60分一下为E。用开...
2句实现.设计一个程序,将从键盘上输入的百分制成绩转换成对应的五分制成绩并输出。90分以上为A,80-89分为B,70-79分为C,60-69分为D,60分一下为E。用开关语。
展开
4个回答
推荐于2018-05-10
展开全部
#include<stdio.h>
int main(void)
{
float score;
char grade;
do
{
printf("please input the score(0-100):");
scanf("%f", &score);
} while (score > 100 || score < 0);
switch ((int)score / 10)
{
case 10:
case 9:
grade = 'A';
break;
case 8:
grade = 'B';
break;
case 7:
grade = 'C';
break;
case 6:
grade = 'D';
break;
default:
grade = 'E';
}
printf("score=%.1f,grade=%c\n", score, grade);
return 0;
}
int main(void)
{
float score;
char grade;
do
{
printf("please input the score(0-100):");
scanf("%f", &score);
} while (score > 100 || score < 0);
switch ((int)score / 10)
{
case 10:
case 9:
grade = 'A';
break;
case 8:
grade = 'B';
break;
case 7:
grade = 'C';
break;
case 6:
grade = 'D';
break;
default:
grade = 'E';
}
printf("score=%.1f,grade=%c\n", score, grade);
return 0;
}
2013-11-10
展开全部
两句?
String[] aaa = new String[]{"t","t","t","t","E","D","C","B","A"}
System.out.print(aaa[分数/10]);
java的代码。其他语言你自己改,很简单的。
String[] aaa = new String[]{"t","t","t","t","E","D","C","B","A"}
System.out.print(aaa[分数/10]);
java的代码。其他语言你自己改,很简单的。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
import java.util.*;
/**
* @author hardneedl
*/
public class ScoreDemo {
private interface Convertor<S,R>{
R convert(S s);
}
private enum ScoreLevel {
A(90,100),
B(80,89),
C(70,79),
D(60,69),
E(0,59)
;
private int low,hi;
ScoreLevel(int low, int hi) {
this.hi = hi;
this.low=low;
}
public String toString() {
return name();
}
}
static private class ScoreLevelConvertor implements Convertor<Integer, ScoreLevel>{
public ScoreLevel convert(Integer s) {
for(ScoreLevel sl:ScoreLevel.values()) {
if (s>=sl.low&&s<=sl.hi)
return sl;
}
return null;
}
}
public static void main(String... args) {
Scanner scanner = new Scanner(System.in);
int i = -9;
while (i < 0 || i > 100) {
System.out.printf("输入分数(大于等于0且小于等于100)");
i = scanner.nextInt();
}
Convertor<Integer,ScoreLevel> c = new ScoreLevelConvertor();
System.out.println(c.convert(i));
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2013-11-10
展开全部
Switch,Case语句
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |