第六周——switch
2015-10-18 16:01
316 查看
问题及代码:
运行结果:
知识点分析:switch(){
case 1: ;break;
case 2: ;break
}
心得及体会:必须要加break语句,不然会执行后面所有语句,还有节约空间。
package practice_01; import java.util.Scanner; public class swith { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub Scanner input =new Scanner(System.in); System.out.println("enter a number"); int number =input.nextInt(); switch(number){ case 0:System.out.println("zero");break; case 1:System.out.println("one");break; case 2:System.out.println("two");break; case 3:System.out.println("three");break; default:System.out.println("oh no");break; } } }
运行结果:
enter a number 1 one
知识点分析:switch(){
case 1: ;break;
case 2: ;break
}
心得及体会:必须要加break语句,不然会执行后面所有语句,还有节约空间。
相关文章推荐
- Linux makefile常用函数
- ios9 qq微信微博等分享用不了的解决方案
- POJ 3187 Backward Digit Sums (递推,bruteforce)
- Request
- ocp-490
- ocp-489
- ocp-488
- SQLSTATE[HY000] [2003] Can't connect to MySQL server on 'XXX'
- ocp-487
- 2016年搜狗笔试第二题 火眼金睛 实现源码
- 【黑马训练营】IOS C语言代码块
- ocp-486
- 自考小感
- No.1 定时器接口timer的设计
- ocp-485
- java.util.Properties类 学习笔记2
- STL数组处理常用函数
- OGRE mesh的渲染流程
- MyBatis SqlSessionFactory的几种常见创建方式
- DELPHI RTTI实现非可视的功能插件