How to implement the ninety-nine multiplication table in Java: Construct a two-layer nested for loop. The outer for loop is used to control the row, and the inner for loop is used to control the multiplication expression on a certain row. Each row Just wrap the output after finishing the output.
Idea:
Construct a two-layer nested for loop: the outer loop is used to control rows, and the inner loop is used to control a certain Multiplication expressions on lines.
It should be noted that after each line is output, a line break is required.
(Recommended tutorial: java video tutorial)
Code implementation:
public class Test1 { public static void main(String[] args){ for(int i=1;i<=9;i++){ for(int j=1;j<=i;j++){ System.out.print(j+"*"+i+"="+(i*j)+" "); } System.out.println(); } } }
Result:
Code implementation:
public class Test { public static void main(String[] args){ for(int i=1;i<=9;i++){ for(int j=1;j<=9;j++){ System.out.print(j+"*"+i+"="+(i*j)+"\t"); } System.out.println(); } } }
Result:
The above is the detailed content of How to implement the ninety-nine multiplication table in java. For more information, please follow other related articles on the PHP Chinese website!