Home  >  Article  >  Java  >  How to implement the ninety-nine multiplication table in java

How to implement the ninety-nine multiplication table in java

王林
王林Original
2020-10-20 14:47:5737060browse

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.

How to implement the ninety-nine multiplication table in java

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:

How to implement the ninety-nine multiplication table in java

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:

How to implement the ninety-nine multiplication table in java

##Related recommendations:

java tutorial

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn