In the following example, we will create and display the Multiplication Table for the given number (9) using for loop
Example
Java Compiler
public class myClass
{
public static void main(String[] args)
{
int table =9;
int length =10;
int i =1;
System.out.print("Multiplication table: "+table);
for(i=1; i<=length; i++)
System.out.format("\n%2d * %d = %d", i, table, i * table);
}
}
In the following example, we will create and display the Multiplication Table for the given number (9) using while loop
Example
Java Compiler
public class myClass
{
public static void main(String[] args)
{
int table =9;
int length =10;
int i =1;
System.out.print("Multiplication table: "+table);
while(i <= length)
{
System.out.format("\n%2d * %d = %d", i, table, i * table);
i++;
}
}
}
In the following example, we will create and display the Multiplication Table for the given number (9) using do while loop
Example
Java Compiler
public class myClass
{
public static void main(String[] args)
{
int table =9;
int length =10;
int i =1;
System.out.print("Multiplication table: "+table);
do {
System.out.format("\n%2d * %d = %d", i, table, i * table);
i++;
}while(i <= length);
}
}