Programming Examples

Java program to check whether input number is a 5digit number or not If it is extract the central digit


Write a program to input an integer and check whether it is a 5-digit number or not. If it is extract the central digit and print it.

Example

INPUT: Enter an integer: 76549

OUTPUT: Central digit: 5

INPUT: Enter an integer: 12976

OUTPUT: Central digit: 9

INPUT: Enter an integer: 126

OUTPUT: Not a 5 digit number

Solution

import java.util.*;
class CentralDigit
{
    public static void main(String arr[])
    {
        int n,m;
        Scanner sc=new Scanner(System.in);
        System.out.println("Enter an integer:");
        n=sc.nextInt();
        if (n>=10000 && n<=99999)
        {
            m=(n/100)%10;
            System.out.println("Central digit:"+m);
        }
        else
            System.out.println("Not a 5 digit number");
    }
}
Output


CCC Online Test 2021 CCC Practice Test Hindi Python Programming Tutorials Best Computer Training Institute in Prayagraj (Allahabad) Best Java Training Institute in Prayagraj (Allahabad) Best Python Training Institute in Prayagraj (Allahabad) O Level Online Test in Hindi Bank SSC Railway TET UPTET Question Bank career counselling in allahabad Sarkari Naukari Notification Best Website and Software Company in Allahabad Sarkari Exam Quiz