Asked by Denial

writ a program that ask a user to inter three integer number and type them to the screen and also print them in different lines .the out put should look like this one .
enter a three integer number:123
1
2
3

Answers

Answered by Denial
this is how i start then i couldn't figure out the rest..

public class Digits2 {

public static void main(String[] args) {
System.out.println("enter a three digit number ");
Answered by Steve
so, the next step will be to accept use input. Check how to do that.
Answered by Denial
okay i used this function to print the out
Scanner in = new Scanner(System.in);
int num = in.nextInt();
but i don't know how to print each number in one line like this
1
2
3
Answered by Steve
you can do one of two things.
(1) use a pattern match to place the digits into an array, then print the array elements.

(2) convert the number to a string, then loop through the string, printing the 1st character and then removing it, till the string is empty.
There are no AI answers yet. The ability to request AI answers is coming soon!

Related Questions