switch 分支

package com.hqyj.javacode.Ifelse;

/**
* switch 分支结构
* 1 整形表达式
* 2 整形常量
* 3case有误break
* 4都不匹配的时候执行default
*/
public class TestSwitch {
public static void main(String[] args) {
//基本认识
int scort =2;
//括号只能输入 当前阶段byte int short char String
switch(scort){
case 1:// case后面只能跟整形常量 要么是常量 要么表达式的值为常量
System.out.println(1); break;
case 2:
System.out.println(2); break;
case 3:
System.out.println(3); break;
default:
System.out.println( "没匹配到");
}
}
}

 

posted @ 2022-03-21 20:41  java小寇  阅读(53)  评论(0)    收藏  举报