循环和条件控制语句
for循环while循环
for(初始化; 布尔表达式; 更新) {
//代码语句
}
增强for循环
声明语句:声明局部变量,变量类型与数组类型相匹配
表达式:表达式是要访问的数组或者框架,或者是返回值为数组或者框架的方法。
for(Map m : 表达式)
{
//代码句子
}
int[] count = new int[]{1,2,3,4,5};
HashMap<String, Integer> map = new HashMap<String, Integer>();
for(int x: count){
//代码句子
}
遍历Hashmap
for(HashMap<String, Integer> map: map){
//代码句子
}
while循环:
while( 布尔表达式 ) {
//循环内容
}
//do…while 循环
do {
//代码语句
}while(布尔表达式);
//break;跳出当前循环
//continue;跳转到下一次循环
条件语句
switch case 语句:
switch(expression){
case value :
//语句
break; //可选
case value :
//语句
break; //可选
//你可以有任意数量的case语句
default : //可选
//语句
}
if else 语句:
if(布尔表达式 1){
//如果布尔表达式 1的值为true执行代码
}else if(布尔表达式 2){
//如果布尔表达式 1未通过,表达式 2的值为true执行代码
}else if(布尔表达式 3){
//如果布尔表达式 1,2未通过,表达式 3的值为true执行代码
}else {
//如果以上布尔表达式都不为true执行代码
}
for循环while循环
for(初始化; 布尔表达式; 更新) {
//代码语句
}
增强for循环
声明语句:声明局部变量,变量类型与数组类型相匹配
表达式:表达式是要访问的数组或者框架,或者是返回值为数组或者框架的方法。
for(Map m : 表达式)
{
//代码句子
}
int[] count = new int[]{1,2,3,4,5};
HashMap<String, Integer> map = new HashMap<String, Integer>();
for(int x: count){
//代码句子
}
遍历Hashmap
for(HashMap<String, Integer> map: map){
//代码句子
}
while循环:
while( 布尔表达式 ) {
//循环内容
}
//do…while 循环
do {
//代码语句
}while(布尔表达式);
//break;跳出当前循环
//continue;跳转到下一次循环
条件语句
switch case 语句:
switch(expression){
case value :
//语句
break; //可选
case value :
//语句
break; //可选
//你可以有任意数量的case语句
default : //可选
//语句
}
if else 语句:
if(布尔表达式 1){
//如果布尔表达式 1的值为true执行代码
}else if(布尔表达式 2){
//如果布尔表达式 1未通过,表达式 2的值为true执行代码
}else if(布尔表达式 3){
//如果布尔表达式 1,2未通过,表达式 3的值为true执行代码
}else {
//如果以上布尔表达式都不为true执行代码
}