How to print the multiplication table of nine using Jav…
Here is an example code in Java for printing the multiplication table of 9.
public class MultiplicationTable {
public static void main(String[] args) {
int n = 9;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= i; j++) {
System.out.print(j + " * " + i + " = " + (i*j) + "\t");
}
System.out.println();
}
}
}
This code utilizes two nested for loops, where the outer loop controls the number of rows and the inner loop controls the number of columns. Within the inner loop, each multiplication expression is printed using the System.out.print() method, with \t used for separation. After the inner loop finishes, the System.out.println() method is used to move to a new line and print the next row of multiplication expressions.