switch-case例题及其与if-else的转换
分享兴趣,传播快乐,增长见闻,留下美好!亲爱的您,这里是LearningYard新学苑。今天小编为大家带来“switch-case例题及其与if-else的转换”,欢迎您的访问。
Share interests, spread happiness, increase knowledge, and leave good news! Dear you, this is the new LearningYard Academy. Today, Xiaobian brings you "switch-case example and its conversion with if-else", welcome your visit.
Java学习入门——switch-case例题及其与if-else的转换
switch-case例题及其与if-else的转换
编写程序:从健盘上输入某一年的month和day要求通过程序输出输入的日期为某年的第几天。
Write a program: input the month and day of a certain year from the keyboard, and request that the input date through the program output be the day of a certain year.
用switch-case语句改写图中程序
Use switch-case statement to rewrite the program in the figure
编写程序:从键盘上读入一个学生成绩,存放在变量score中,根据score的值输出其对应的成绩等级:
score>=90 等级: A
70<=score<90 等级: B
60<=score<70 等级: C
score<60 等级: D
Write a program: read a student's grade from the keyboard, store it in the variable score, and output its corresponding grade according to the value of the score:
score>=90 Grade: A
70<=score<90 Grade: B
60<=score<70 Grade: C
score<60 Grade: D
switch-case与if-else转换说明
① 凡是可以使用switch-case的结果都可以使用if-else。反之不成立。
② 在写分支结构时,出现既可以使用switch-case(case的取值情况不能太多),又可以使用if-else,优先使用switch-case(原因switch-case的执行效率稍高)。
switch-case and if-else conversion description
① Any result that can use switch-case can use if-else. The opposite does not hold.
② When writing a branch structure, it appears that you can use switch-case (the value of the case can not be too many), and you can use if-else, and switch-case is preferred (because the execution efficiency of switch-case is slightly higher).
今天的分享就到这里了。如果您对今天的文章有独特的想法,欢迎给我们留言,让我们相约明天,祝您今天过得开心快乐!
That's it for today's sharing. If you have a unique idea about today’s article, Welcome to leave us a message. Let us meet tomorrow, I wish you a happy day today!
END
翻译:来自Googl翻译
本文由LearningYard新学苑原创,欢迎关注,带你一起长知识。
排版:谢宗佑
文字:谢宗佑
审核:李小雪
本文【switch case语句的用法C语言】由作者: 外键 提供,本站不拥有所有权,只提供储存服务,如有侵权,联系删除!
本文链接:https://www.cuoshuo.com/blog/4246.html