switch语法在项目使用的频率很低,今天看到一个相关的例子引发一些思考,,同时自己也写了一些简单的例子如下: 实例1: int dayOfWeek = 5; switch (dayOfWeek){ default: System.out.println("default"); case 1: System.out.println("1111"); case 2: System.out.println("2222"); case 4: Syste…
switch语句下的变量声明和定义的问题: switch...case...语句中存在声明和定义会出现一些问题.这个由switch语法特性决定的, switch中每个case都是平等的层次,区别于一般的if else语句,我们知道swich的case语句可以这样写: switch (i) { case 1: case 2: int n = 0; break; case 3: break; default: break; } 所以整个switch语句处在同一个代码块中,只不过有多个case语句,既…
时间有限,简单记一些常用的,麻烦的不写了 定义变量:可以连续定义,也可以单个定义 var a int int类型 var a="ds" 默认string类型 a:="string" :=前面不可以有var 上面三种属于等价的 连续定义 var x1,x2,x3 int =1,2,3 name1,name2,name3:="mu","bai","xu" 基本数据类型 int int16,int32…
Java 分支结构 - if...else/switch 顺序结构只能顺序执行,不能进行判断和选择,因此需要分支结构. Java 有两种分支结构: if 语句 switch 语句 if 语句 一个 if 语句包含一个布尔表达式和一条或多条语句. 语法 if 语句的用语法如下: if(布尔表达式) { //如果布尔表达式为true将执行的语句 } 如果布尔表达式的值为 true,则执行 if 语句中的代码块,否则执行 if 语句块后面的代码. Test.java 文件代码: public clas…
public class Test{ public static void main(String args[]){ int x = 10; if(x<20){ System.out .println("这就是if语句"); } }} 这是 if 语句 public class Test{ public static void main(String args[]){ int x=30; if(x<10){ System.out.println("这是if语句&q…