Print 9*9 multiplication table using java
Certainly! Below is a simple Java program that prints a 9x9 multiplication table:
public class MultiplicationTable {
public static void main(String[] args) {
// Print the header
System.out.print(" ");
for (int i = 1; i <= 9; i++) {
System.out.printf("%4d", i);
}
System.out.println();
// Print a separator line
System.out.println(" ---------------------------------");
// Print the multiplication table
for (int i = 1; i <= 9; i++) {
System.out.printf("%4d|", i); // Print the row header
for (int j = 1; j <= 9; j++) {
System.out.printf("%4d", i * j); // Print the product
}
System.out.println(); // Move to the next line
}
}
}
printf
method is used for formatted output, ensuring that the numbers align properly in columns.MultiplicationTable.java
.javac MultiplicationTable.java
.java MultiplicationTable
.You should see the 9x9 multiplication table printed in a formatted manner.