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

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

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

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]);
        do
        {  
            System.out.println(x+"*"+n+"="+x*n);
            x++;
        }while(x<=10);
    }
}	

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

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


88 . Write a Java-program to display the Table using do while loop ?
89 . Write a Java-program to display vowels using continue statement ?
90 . Write a Java-program to display the whose values divisible by 2 and 3 Continue statement in java ?
91 . Write a Java-program to Break the loop which number is divisible by 2 and 3 in java ?
92 . Write a Java-program to print a to z character
93 . Write a Java-program to print A to Z character
94 . Write a Java-program to print character numbers
95 . Write a Java-program to print symbols
96 . Write a Java-program to print ASCII values of a to z
97 . Write a Java-program to print ASCII values of A to Z
98 . Write a Java-program to print ASCII values of Numbers