Java Program to Check Given Input is Digit or Not

In this tutorial you will be learning Writing Java Program to check a Given input is Digit or not.

For Example:

Example 1:

Suppose a given input is 10

Then output should be “Given input is digit”.

Example 2:

And for the input A or any character or any symbol

The output should be “Given input is not a digit”.

Program To Check given input is Digit or not in Java

import java.util.*;
public class Main
{
  public static void main (String[] args)
  {
    System.out.println("Program to check digit or not in Java");
    Scanner sc = new Scanner (System.in);
    System.out.println ("Enter a input");
    char ch = sc.next ().charAt (0);
     if(ch>='0' && ch<='9')
	 {
	  	System.out.println("Given Input is Digit.");
	 }
	 else
	 {
	  	System.out.println("Given Input is Not Digit.");
	 }
  }
}

Output 1:

Program to check digit or not in Java
Enter a input
34
Given Input is Digit.

Output 2:

Program to check digit or not in Java
Enter a input
ww
Given Input is Not Digit.
Scroll to Top