Online Java Compiler By
JavaTpoint.com
import java.util.Scanner; public class JavaCharacterisDigitExample4 { public static void main(String[] args) { // Ask the user to enter the first character. System.out.print("Enter the first character:"); // Use scanner to get the user input. Scanner s1 = new Scanner(System.in); char value1 = s1.nextLine().toCharArray()[0]; // Check whether the input is digit or not. boolean check1 = Character.isDigit(value1); // Print the result if(check1){ System.out.print("The character \'"+value1+"\' is a digit.\n"); } else{ System.out.print("The character \'"+value1+"\' is not a digit.\n"); } // Ask the user to enter the second character. System.out.print("Enter the first character:"); // Use scanner to get the user input. Scanner s2 = new Scanner(System.in); char value2 = s2.nextLine().toCharArray()[0]; // Check whether the input is digit or not. boolean check2 = Character.isDigit(value2); // Print the result. if(check2){ System.out.print("The character \'"+value2+"\' is a digit.\n"); } else{ System.out.print("The character \'"+value2+"\' is not a digit.\n"); } } }
Output