// if 语句
/*
if(布尔表达式) {
//如果布尔表达式为true将执行的语句
}
*/
// if...else 语句
/*
if(布尔表达式) {
//如果布尔表达式为 true 将执行的语句
} else {
//如果布尔表达式为 false 将执行的语句
}
*/
// if...else if...else 语句
/*
if(布尔表达式 1){
//如果布尔表达式 1的值为true执行代码
}else if(布尔表达式 2){
//如果布尔表达式 2的值为true执行代码
}else if(布尔表达式 3){
//如果布尔表达式 3的值为true执行代码
}else {
//如果以上布尔表达式都不为true执行代码
}
*/
// if ... if 语句
/*
if(布尔表达式 1){
////如果布尔表达式 1的值为true执行代码
if(布尔表达式 2){
////如果布尔表达式 2的值为true执行代码
}
}
*/
// 示例
/*
public class Control {
public static void main(String args[]) {
// 判断成绩
double score = 98 ;
if (score > 90) {
System.out.println("Great");
} else if (score > 80 && score < 90) {
System.out.println("Good");
} else {
System.out.println("小白痴!!!");
}
}
}
*/
// Java 循环结构 - while / do...while / for
// while 循环
/*
while (布尔表达式){
循环内容
}
*/
/*
public class Control {
public static void main(String args[]) {
// 100 以内数 相加
int sum = 0 ;
int current = 1 ;
while (current <= 100) {
sum += current ;
current ++ ;
}
System.out.println(sum);
}
}
*/
// do... while 循环
/*
do {
代码语句
}while(布尔表达式);
*/
/*
public class Control {
public static void main(String arrgs[]) {
int sum = 0 ;
int current = 1 ;
do {
sum += current ;
current ++ ;
} while (current <= 100);
System.out.println(sum);
}
}
*/
// for 循环
/*
for(初始化; 布尔表达式; 更新) {
//代码语句
}
*/
/*
public class Control {
public static void main(String args[]) {
int sum = 0;
for (int current = 1; current <= 100; current ++ ){
sum += current ;
}
System.out.println(sum);
}
}
*/
// 循环控制
// break ( 直接结束循环条件)
// continue ( 跳过本次循环,下面的条件继续)
Java 程序逻辑控制
猜你喜欢
转载自blog.csdn.net/u011327801/article/details/93337657
今日推荐
周排行