write a java program to check number is five digit or not
Answers
Answer:
I am trying to complete an assignment, and I have almost fully completed it but I am have some trouble figuring out the last part.
How to: Check whether the number you received has five digits or not. Terminate gracefully if it doesn’t by notifying that the number should have 5 digits.
I've tried some stuff but I cannot get it to check correctly.
Explanation:
Here is my code:
import java.util.Scanner;
public class Five
{
public static void main( String args[] )
{
Scanner input = new Scanner( System.in );
int number;
int digit1;
int digit2;
int digit3;
int digit4;
int digit5;
System.out.print( "Enter a five digit integer: " );
number = input.nextInt();
digit1 = number / 10000;
digit2 = number % 10000 / 1000;
digit3 = number % 10000 % 1000 / 100;
digit4 = number % 10000 % 1000 % 100 / 10;
digit5 = number % 10000 % 1000 % 100 % 10;
System.out.printf( "Digits in %d are %d %d %d %d %d/n",
number, digit1, digit2, digit3, digit4, digit5 );
I HOPE YOU LIKE