1、复合语句
public static void main(String[] args){ int x; { ········ ········复合语句1 ········ { ········ ········复合语句2 ········ } } }
2、条件语句
- if语句
if(条件,布尔表达式){ 执行语句; }
不加{}也没有错误,但是为了可读性,加上为好。
- if...else语句
- if...else if多分支语句
3、switch多分支语句
switch(str){ case str1: break; case str2: break; default: }
4、循环语句
- while循环语句
- do...while循环语句
- for循环语句
for(表达式1;表达式2;表达式3){ }
5、foreach语句
java的一个特殊简化版本,不能完全取代for语句,但是对于遍历数组还是会方便。
int arr[]={1,4,7}; for(int x : arr){ execute; }
来源:https://www.cnblogs.com/hasz/p/12199324.html