← All resources

Write a program in Java to input a character and print whether it is a digit or not. Using Switch case

This program uses the property of fall through in Switch Case

import java.util.*;
public class Digit_Switch
{
    public static void main()
    {
        Scanner sc = new Scanner(System.in);
        char ch;
        System.out.println("Enter a character:");
        ch = (sc.next()).charAt(0);
        switch(ch)
        {
            case '0':
            case '1':
            case '2':
            case '3':
            case '4':
            case '5':
            case '6':
            case '7':
            case '8':
            case '9':
            System.out.println("The character is a digit.");
            break;
            default:
            System.out.println("The character is not a digit.");
        }
    }
}