Write a Java-program to check the given character is number or not

Write a Java-program to check the given character is number or not

Program
public class Main
{
	public static void main(String args[])
	{
        char ch='4';
        if(ch>='0' && ch<='0')
        {
            System.out.println("Number");
        }
        else
        {
            System.out.println("Not a Number");
        }
	}
}	

Output:

Number

Using CommandLine Arguments
public class Main
{
	public static void main(String args[])
	{
        char ch;
        ch=args[0].charAt(0);
        if(ch>='0' && ch<='9')
        {
            System.out.println("Number");
        }
        else
        {
            System.out.println("Not a Number");
        }
	}
}	

Output:

Number

Using Scanner Class
import java.util.*;
public class Main
{
	public static void main(String args[])
	{
        char ch;
        Scanner s=new Scanner(System.in);
        System.out.println("Enter Number");
        ch=s.next().charAt(0);
        if(ch>='0' && ch<='9')
        {
            System.out.println("Number");
        }
        else
        {
            System.out.println("Not a Number");
        }
	}
}	

Output:

Enter Number
4
Number





More Questions


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
37 . Write a Java-program to print Max Number amoung the three numners using else if
38 . Write a Java-program to check the given character is vowel or consonant( Character must be small letter)
39 . Write a Java-program to check Odd or Even number program using nested if condition(value must be positive)
40 . Write a Java-program to check Odd or Even number using switch
41 . Write a Java-program to check Vowel or Consonant using switch
42 . Write a Java-program to display 1 to 10 values using for loop