For statement application: multiplication table, for statement multiplication table
Multiplication table:
For statement application:
1:
2: public class chengfa {
3: public static void main(String[] args) {
4: //int i;
5: for(int i=1;i<=9;i++){
6: int j=1;
7: for(;j<=i;j++){
8: System. out. print (j + "×" + I + "=" + (I * j) + "\ t"); // \ t
9: }
10: System.out.println();
11: }
12: }
13: }
14:
Output result
1 × 1 = 1
1 × 2 = 2 2 × 2 = 4
1x3 = 3 2x3 = 6 3x3 = 9
1 × 4 = 4 2 × 4 = 8 3 × 4 = 12 4 × 4 = 16
1x5 = 5 2x5 = 10 3x5 = 15 4x5 = 20 5x5 = 25
1 × 6 = 6 2 × 6 = 12 3 × 6 = 18 4 × 6 = 24 5 × 6 = 30 6 × 6 = 36
1 × 7 = 7 2 × 7 = 14 3 × 7 = 21 4 × 7 = 28 5 × 7 = 35 6 × 7 = 42 7 × 7 = 49
1x8 = 8 2x8 = 16 3x8 = 24 4x8 = 32 5x8 = 40 6x8 = 48 7x8 = 56 8x8 = 64
1x9 = 9 2x9 = 18 3x9 = 27 4x9 = 36 5x9 = 45 6x9 = 54 7x9 = 63 8x9 = 72 9 × 9 = 81
Use JAVA to print the 9-9 multiplication table with the for statement.
Public class T1 {
Public static void main (String [] args ){
Int k = 1;
For (int I = 1; I <= 9; I ++ ){
System. out. print ("");
While (k <= 9 ){
System. out. print (k + "");
K ++;
}
System. out. println ("");
System. out. print (I + "");
For (int j = 1; j <= I; j ++ ){
System. out. print (I * j + "");
}
System. out. println ("");
}
}
}
Write the 9 × 9 multiplication table of the for statement in C language and rewrite it to the type of the while statement and the do-while statement.
// ============ For form ============
Main ()
{
Int I, j;
For (I = 1; I <= 9; I ++)
{
For (j = 1; j <= I; j ++)
Printf ("% d * % d = % d \ t", j, I, I * j );
Printf ("\ n ");
}
Getch ();
}
// =========== While () form ============================
Main ()
{
Int I, j;
I = 1;
J = 1;
While (I <= 9)
{
While (j <= I)
{
Printf ("% d * % d = % d \ t", j, I, I * j );
J ++;
}
I ++;
Printf ("\ n ");
}
Getch ();
}
Hope to help you!