Write a Java program to break an integer into a sequence of individual digits. Test Data: Input six non-negative digits: 123456 Expected Output:1 2 3 4 5 6
Answers
Answer:
import java.util.Scanner;
class Integer
{
// function to break an integer into a
// sequence of individual digits
static void integerToDigits ( )
{
Scanner sc = new Scanner( System.in);
System.out.println("Enter a six digit non
negative integer");
int num = sc.nextInt( );
int a = num/100000;
int b = (num%100000)/10000;
int c = (num%10000)/1000;
int d = (num%1000)/100;
int e = (num%100)/10;
int f = num%10;
System.out.println("Sequence of
individual digits of the entered integer
is "+a+"\t"+b+"\t"+c+"\t"+d+"\t"+e+"\t"+f);
}
}
Explanation:
OUTPUT
Enter a six digit non negative integer
123456
Sequence of individual digits of the entered integer is 1 2 3 4 5 6