Write a Java-program to check the given number is valid or invalid(value must between 20 and 30)

Write a Java-program to check the given number is valid or invalid(value must between 20 and 30)

Program
public class Main
{
	public static void main(String args[])
	{
        int x=10;
        if(x>=20 && x<=30)
        {
            System.out.println("Valid Number");
        }
        else
        {
            System.out.println("Invalid Number");
        }
	}
}	

Output:

Invalid Number

Using CommandLine Arguments
public class Main
{
	public static void main(String args[])
	{
        int x;
        x=Integer.parseInt(args[0]);
        if(x>=20 && x<=30)
        {
            System.out.println("Valid Number");
        }
        else
        {
            System.out.println("Invalid Number");
        }
	}
}	

Output:

Invalid Number

Using Scanner Class
import java.util.*;
public class Main
{
	public static void main(String args[])
	{
        int x;
        Scanner s=new Scanner(System.in);
        System.out.println("Enter x Value");
        x=s.nextInt();
        if(x>=20 && x<=30)
        {
            System.out.println("Valid Number");
        }
        else
        {
            System.out.println("Invalid Number");
        }
	}
}	

Output:

Enter x value
10
Invalid Number





More Questions


26 . Write a Java-program to check the given number is valid or invalid(value must divisible by 2 and 3)
27 . Write a Java-program to check the given number is valid or invalid(value must divisible by 2 and 3 not 4)
28 . Write a Java-program to check the given number is valid or invalid(value must divisible by 2 and 3 not 4 using 2 conditions)
29 . Write a Java-program to check the given number is valid or invalid(value must between 20 and 30)
30 . Write a Java-program to check the given character is vowel or consonant
31 . Write a Java-program to check the given character is small letter or not
32 . Write a Java-program to check the given character is capital letter or not
33 . Write a Java-program to check the given character is number or not
34 . Write a Java-program to check the given character is symbol letter or not
35 . Write a Java-program to calculate simple interest with following condtions
36 . Write a Java-program to print age