0% found this document useful (0 votes)
2 views

program

The Java program prompts the user to enter a six-digit integer and checks if the input meets the criteria. If the number is not six digits, it displays an error message. If valid, it extracts and prints each digit of the number using a for loop, although there is an error in the variable name used for output.

Uploaded by

zabronjoshua003
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

program

The Java program prompts the user to enter a six-digit integer and checks if the input meets the criteria. If the number is not six digits, it displays an error message. If valid, it extracts and prints each digit of the number using a for loop, although there is an error in the variable name used for output.

Uploaded by

zabronjoshua003
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

import java.util.

Scanner;

public class SixDigitsSeparator{

//Main method
public static void main(String [] args){

//Use scanner object to read user input from package


Scanner input = new Scanner(System.in);

// Declare the variables


int number;
int result;

//Prompt a user to enter a 6 digits integer


System.out.println("Enter a six digits number:");
number = input.nextInt();

//Check if a number satisfy the condition


if (number < 100000 || number > 999999){

System.out.println("Error:The number must be exactly six


digits.");

}
else{

System.out.println("");
}
//Extract each digit separately by for loop
for (int i = 5; i >= 0; i--){

//Call the another method to extract digit

int digit = number / (int) Math.pow(10, i) % 10;

System.out.println("The result is:" + digits);

}
}

You might also like