java控制语句
2015-07-15 15:28
465 查看
控制语句的使用
if else的使用
switch 的使用
1.switch(a)的值只能是 byte,short,int类型;
2.注意case()break,退出循环的使用;
if else的使用
import java.util.*; public class ForXunhuan { public static void main(String[] args) { Scanner input = new Scanner(System.in); int a = 0; while (true) { System.out.println("请正确输入成绩:0~100"); a = input.nextInt(); if(a>=0&&a<=100) break; } if (a < 100 && a >= 90) { System.out.println("优秀"); } else if (a > 80) { System.out.println("良"); } else if (a > 70) { System.out.println("中"); } else if (a > 60) { System.out.println("差"); } else { System.out.println("不及格"); } } }
switch 的使用
1.switch(a)的值只能是 byte,short,int类型;
2.注意case()break,退出循环的使用;
import java.util.*; public class Sxuhuan { public static void main(String[] args) { int a; int b; Scanner input = new Scanner(System.in); while (true) { System.out.println("请正确输入成绩:0~100"); a=input.nextInt(); if(a>=0&&a<101) break; } b=a/10; switch(b){ case 10: case 9: System.out.println("优秀"); break; case 8: System.out.println("良"); break; case 7: System.out.println("中"); break; case 6: System.out.println("差"); break; default: System.out.println("不及格"); break; } } }
相关文章推荐
- 【转】Java并发编程:volatile关键字解析
- JAVA代码,正则表达式验证
- java控制语句的使用
- JAVA,本地上传图片到服务器
- JAVA,hibernate配置文件加密
- 深入浅出 Java Concurrency (5): 原子操作 part 4
- eclipse4.3集成maven,svn
- MyEclipse的Java使用opencv配置
- java HashMap两种遍历方式的深入研究
- java解析properties配置文件
- spring 定时器的使用
- [Spring MVC] - JSP + Freemarker视图解释器整合
- Java错误提示-------。。。。。cannot be resolved 。???
- JAVA获取客户端请求电脑IP,操作系统等等各种信息
- spring mvc 通过字节流返回图像
- java.lang.OutOfMemory分析
- 解决 Eclipse 卡在Android SDK Content Loader 问题
- JAVA下wordpress加密
- Java 类路径扫描
- java 获取文字首写字母