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

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

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

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=1,n;
        n=Integer.parseInt(args[0]);
        while(x<=10)
        {  
            System.out.println(x+"*"+n+"="+x*n);
            x++;
        }
    }
}	

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=1,n;
        Scanner s=new Scanner(System.in);
        System.out.println("Enter n value : ");
        n=s.nextInt();
        while(x<=10)
        {  
            System.out.println(x+"*"+n+"="+x*n);
            x++;
        }
    }
}	

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


71 . Write a Java-program to print sum of even or odd numbers based on the N value using single while loop ?
72 . Write a Java-program to display the Table using while loop ?
73 . for and while difference program(Factorial Number using while Loop (value must be positive number))
74 . Write a Java-program to display 1 to 10 values using do while loop ?
75 . Write a Java-program to display 10 to 1 values using do while loop
76 . Write a Java-program to display 1 to n values using do while loop
77 . Write a Java-program to display display Even Numbers using do while loop
78 . Write a Java-program to display Even Number or Odd Number based on the N value using do while loop
79 . Write a Java-program to display Even Number or Odd Number based on the N value using single do while loop
80 . Write a Java-program count the number of divisible numbers in a given range(1-100) using do while loop ?
81 . Write a Java-program to print Factorial Number using do while loop ?