您的位置:首页 > 其它

第六周——switch

2015-10-18 16:01 316 查看
问题及代码:

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语句,不然会执行后面所有语句,还有节约空间。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: