1. The for loop
Format: the for (initialization conditions; Condition judgment; Conditions change) {
Repeat the code;
}
Eg: please 1 + 2 + 3... + 100 and
Public class Test {
Public static void main (String [] args) {
Int sum=0;
for (int i=1; i<=100; I++) {
Sum=sum + I;
}
System.out.println(sum);
}
}
The for loop of nested
In a for loop statement to one or more nested loop;
Example: use for nested loop to realize jiujiu multiplication tables:
2: fixed value judgment
The switch (expression) {
Case 1:
Statements body 1;
break;
Case value 2:
2 statements body;
break;
.
Default:
N the statement,
break;
}
Note: if there is no break, statement in case the effect of penetration, in the event of penetration, will not satisfy conditions determine whether the following case, direct statement execution body, know to meet the next break, or the end of the switch beyond constant-like statements,
Example: a Boolean variable b=false;
Want to use a switch statement to determine the b if b value is true, just print "true", if the value of b is false, false printing;
1.
The switch (b + "") {
Case "true" :
System. The out. Println (" true ");
break;
A case of "false" :
System. The out. Println (" false ");
break;
}
2.
int n;
{if (b)
N=0;
} else {
n=1;
}
The switch (n) {
Case 0:
System. The out. Println (" true ");
break;
Case 1:
System. The out. Println (" false ");
break;
}
CodePudding user response:
Learn to learn,,,,,,,