if语句和switch语句
2015-12-03 15:25
197 查看
1.基本写法
if
if(逻辑表达式){语句;}else if{语句;else{语句;}
switch
switch(变量){case 常量值:语句;break;default:语句;}
2.举例
if else语句
2.switch语句
if
if(逻辑表达式){语句;}else if{语句;else{语句;}
switch
switch(变量){case 常量值:语句;break;default:语句;}
2.举例
if else语句
public class ccc { /** * @param args */ public static void main(String[] args) { int a = 10 if(a>18) { System.out.println("你已经成年"); } else if(a=18) { System.out.println("你刚满十八岁"); } else { System.out.println("你还未成年"); } // // TODO 自动生成的方法存根 } }
2.switch语句
public class ccc { /** * @param args */ public static void main(String[] args) { int a = 5; switch(a) { case 0: System.out.println("你是个好人"); break; case 5: System.out.println("你不是好人"); break; default: System.out.println("输入有误"); break; } // TODO 自动生成的方法存根 } }
相关文章推荐
- 插入排序详解
- Fabrc
- 使用Eclipse自带的Maven插件创建Web项目时报错: Could not resolve archetype org.apache.maven.archetypes:maven-arche
- 关于张正友标定法
- Spring JdbcTemplate方法详解
- html高度随分辨度改变而改变
- JSP+Servlet 无数据库模拟登录过程
- Hive_6. 数据聚合 -- Group By & Grouping_SETS & RollUp & CUBE & Having
- webView实现图文混排
- 向上弹出菜单jQuery插件
- MySQL字符串函数:字符串截取
- css3是什么
- dTree JS 基本用法
- Android SlidingDrawer使用
- Oracle SQL实现分页查询
- ie9 提示'console' 未定义问题的解决方法
- log4j 配置详解
- log4j 配置详解
- log4j 配置详解
- log4j 配置详解