Write a Java-program to display the Table using for loop ?

Write a Java-program to display the Table using for loop ?

Program
public class Main
{
    public static void main(String args[])
    {
        int x,n=5;
        for(x=1; x<=10; x++)
        {
            System.out.println(x+" * "+n+" = "+(x*n));  
        }
    }
}	

Output:

1 * 5 = 5
2 * 5 = 10
3 * 5 = 15
4 * 5 = 20
5 * 5 = 25
6 * 5 = 30
7 * 5 = 35
8 * 5 = 40
9 * 5 = 45
10 * 5 = 50

Using CommandLine Arguments
public class Main
{
    public static void main(String args[])
    {
        int x,n;
        n=Integer.parseInt(args[0]);
        for(x=1; x<=10; x++)
        {
            System.out.println(x+" * "+n+" = "+(x*n));  
        }
    }
}	

Output:

1 * 5 = 5
2 * 5 = 10
3 * 5 = 15
4 * 5 = 20
5 * 5 = 25
6 * 5 = 30
7 * 5 = 35
8 * 5 = 40
9 * 5 = 45
10 * 5 = 50

Using Scanner Class
import java.util.*;
public class Main
{
    public static void main(String args[])
    {
        int x,n;
        Scanner s=new Scanner(System.in);
        System.out.println("Enter n value");
        n=s.nextInt();
        for(x=1; x<=10; x++)
        {
            System.out.println(x+" * "+n+" = "+(x*n));  
        }
    }
}	

Output:

Enter n value : 5
1 * 5 = 5
2 * 5 = 10
3 * 5 = 15
4 * 5 = 20
5 * 5 = 25
6 * 5 = 30
7 * 5 = 35
8 * 5 = 40
9 * 5 = 45
10 * 5 = 50





More Questions


56 . Write a Java-program to print sum of even or odd numbers based on the N value using single for loop ?
57 . Write a Java-program to display the Table using for loop ?
58 . Write a Java-program to display 1 to 10 values using while loop ?
59 . Write a Java-program to display 10 to 1 values using while loop
60 . Write a Java-program to display 1 to n values using while loop
61 . Write a Java-program to display display Even Numbers using while loop
62 . Write a Java-program to display Even Number or Odd Number based on the N value using while loop
63 . Write a Java-program to display Even Number or Odd Number based on the N value using single while loop
64 . Write a Java-program count the number of divisible numbers in a given range(1-100) using while loop ?
65 . Write a Java-program to print Factorial Number using while loop ?
66 . Write a Java-program to print Factorial of upto N Numbers using while loop ?