JAVA--swich选择结构

  • switch关键字后面小括号里的值,放一个整型变量(表达式)、字符串变量(表达式)或枚举类型。
  • switch选择结构的条件只能是等值的判断。

例子:

    public class Award{
    	public static void main(String[] args){
    	Scanner scan = new Scanner(System.in);
    	System.out.println("`请输入名次“:");
    	int ranking = scan.nextInt();
    	switch(ranking ){
    	case 1:
	    System.out.println("参加麻省理工大学组织的1个月夏令营");
    	break;
    	case 2:	
            System.out.println("奖励一台笔记本电脑");
            break;
        case 3:
            System.out.println("奖励一个移动硬盘");//
     	default:
     	    System.out.println("没有奖励");
    	  }
     	}
  }

猜你喜欢

转载自blog.csdn.net/weixin_42141323/article/details/88541429
今日推荐