语法结构
.
选择结构
.
运算符的优先级: 从大到小: 算 比 逻 条 或
1:选择结构 if
if(表达式){ 表达式为true,则进入到代码块。
代码块 }
2: if else if(表达式){
表达式为true的代码块
}else{
表达式为false 的代码块
}
## 3: 嵌套 if else
if(表达式){
表达式为true.进入代码块
if(表达式){
}else{
}
}else{
表达式为false,进入代码块
if(表达式){
}else{
}
}
等值判断结构:
switch case break default
switch()括号中,只能使用的类型 String int byte short char 枚举
case 值 : case后面要跟随值。
break; 当代码块遇到break.立即跳出整个switch结构。 可以不写break; 代码块继续向下执行。
default;缺省的,默认的。 不满足以上所有情况,就执行default中的代码。
if else if 不能否使用switch替换。
swithc 不能使用if else if 替换。
.
循环结构
.
while 循环。
while(表达式){
代码块 break; 结束循环体。
}
当表达式为true时,进入循环体。当表达式为false时,结束循环。
循环三个要素:
1: int i=0;
2: i<10
3: i++
do while循环*
while 循环是先判断表达式为true,进入循环。
do while 循环,先执行一次,再判断表达式,为true进入循环。为false结束循环
java中的方法
.
方法必须,先定义,后调用。
方法1:无参数,无返回值的方法。public static void show(){ }
方法2: 无参数,有返回值的方法。public static int show(){ return 注意,一个方法中,只能返回一个值。 return之后不能有代码}
方法3: 有参数,无返回值的方法。public static void show(int a,double b,char c……){ 注意,参数只定义。不能赋值。}
方法4: 有参数,有返回值的方法。 public static double show(int a,int b,String d…………){ return }