Code analysis:
for (int
I = initial condition; condition continues; conversion (i ++)) {
}
Set good condition can begin the second step
In the for (int i = start condition; condition continues; conversion (i ++)) {
In addition in a nested loop to reach a joint relationship to let him get
for (int
J = starting condition; condition continues; conversion (J ++)) {
Analysis: For example, we make a multiplication table 9 order that our code continues that i <= 9
Conditions of the second cycle should be j <= i is equal to him when i stopped with no duplicate parameter
If the second cycle directly for (int. 1 = J; J <=. 9;
J ++) will be the case
11=1 12=2
13=3 14=4 15=5
16=6 17=7 18=8
1*9=9
21=2 22=4
23=6 24=8 25=10
26=12 27=14 28=16
2*9=18
31=3 32=6
33=9 34=12 35=15
36=18 37=21 38=24
3*9=27
41=4 42=8
43=12 44=16 45=20
46=24 47=28 48=32
4*9=36
51=5 52=10
53=15 54=20 55=25
56=30 57=35 58=40
5*9=45
61=6 62=12
63=18 64=24 65=30
66=36 67=42 68=48
6*9=54
71=7 72=14
73=21 74=28 75=35
76=42 77=49 78=56
7*9=63
81=8 82=16
83=24 84=32 85=40
86=48 87=56 88=64
8*9=72
91=9 92=18
93=27 94=36 95=45
96=54 97=63 98=72
9*9=81
System.out.print (i + " " + J + "=" + (i J) + ""); this is so he can generate (9 * 9 = 81)
Such a structure
Behind the first write cycle System.out.println (); to achieve the effect is to make wrap nested loops after completion
Code demonstrates:
public class sd0514 {
public static void main(String[] args) {
for (int i = 1; i <=9; i++) {
for (int j =1 ; j <=i; j++) {
System.out.print(i+""+j+"="+(ij)+" ");
}
System.out.println();
}
}
}
result:
1*1=1
21=2 22=4
31=3 32=6
3*3=9
41=4 42=8
43=12 44=16
51=5 52=10
53=15 54=20 5*5=25
61=6 62=12
63=18 64=24 65=30
66=36
71=7 72=14
73=21 74=28 75=35
76=42 7*7=49
81=8 82=16
83=24 84=32 85=40
86=48 87=56 88=64
91=9 92=18
93=27 94=36 95=45
96=54 97=63 98=72
9*9=81