数据测试
if ...else if and else;
- 正确数据
- 边界数据
- 错误数据
if (score >100 || score<0) { System.out.println(" illegal input"); \\ the illegal input } else if (score >=95 || score<=100) { System.out.println("####"); \\the border and the true statistic } else if (score>=0||score <=95){ System.out.println("###") }
switch
switch(variable){
case value1:
statemen;
break; \\the break of each case in not a must, but if it disappear, it
\\program will execute the next case until the break appear.
case value2:
statement;
break;
......
default:
statement \\the default branch doesnot need a break statement
}
public static void main(String[] args){
int num =3;
switch (num){
case 1:
System.out.println("the value is 1");
break;
case 2:
System.out.println("the value is 2");
break;
case 3:
System.out.println("the value is 3");
break;
}
}
while loop
while (boolean expression){
statement; \\if the boolean expression is true the loop will continue
\\executing;
}
for loop
for (initial; boolean expression; update){
statement;
}
\\
public static void main(String[] args){
for (int x=1; x<=10; x++){
System.out.println(x);
}
}
do while
do{
System.out.println(x); \\do...while loop is executed at least once
} while (boolean expression) \\the loop will end until the boolean expression is false