I am trying to create an application that will:
1) ask the person to enter a number (ex: 321)
2) the application will display each number on a line
ex:3
2
1

Rules: Don't use looping and don't use arrays

Someone told me it could be done but I can't find it!!

What I've done:

Scanner scan = new Scanner(System.in);
int numb;
numb = scan.nextInt();

but what next ?

I am trying to create an application that will:
1) ask the person to enter a number (ex: 321)
2) the application will display each number on a line
ex:3
2
1

Rules: Don't use looping and don't use arrays

Someone told me it could be done but I can't find it!!

What I've done:

Scanner scan = new Scanner(System.in);
int numb;
numb = scan.nextInt();

but what next ?

use the charAt(int index) method in the string class to read in or display a specific character of the string, this would then make you have to use nextLine() and not nextInt() or if you read each number in separately the just display is each time using the System.out.println(numb);

do you know up front how long (many digits) your number will be?

use the charAt(int index) method in the string class to read in or display a specific character of the string

that's one possibility indeed, but you would have to know the number of digits, if they're not known up front, I 'm a bit puzzled about how to do this without a loop.

that's one possibility indeed, but you would have to know the number of digits, if they're not known up front, I 'm a bit puzzled about how to do this without a loop.

Hmm maybe the OP could use the Length() method on the string and use many if statements to check the value. But yes without a loop it would be a problem, but maybe the lecturer gave a specific number for the example

PS: we should use, only

println()
print()
next()
nextLine()

you are not allowed to use variable.method()

PS: the number to enter will be 3 digits

PS: we should use, only

println()
print()
next()
nextLine()

you are not allowed to use variable.method()

well it depends, as stultuske said do you know how many digits will be entered? and if so would you not be accepting each input separately? then just use the println() on each digit read.

read it in as a String, using the
next() method
then:
print them using .charAt(0) .charAt(1) .charAt(2)

read it in as a String, using the
next() method
then:
print them using .charAt(0) .charAt(1) .charAt(2)

u r not allowed to use charAt() :\

AAARGH!!! silly me :P

Scanner scan = new Scanner(System.in);
int numb = scan.nextInt();
int t = numb/100;
System.out.println("" + t);
numb -= (t*100);
t = numb/10;
System.out.println("" + t);
numb -= (t*10);
System.out.println("" + numb);

AAARGH!!! silly me :P

Scanner scan = new Scanner(System.in);
int numb = scan.nextInt();
int t = numb/100;
System.out.println("" + t);
numb -= (t*100);
t = numb/10;
System.out.println("" + t);
numb -= (t*10);
System.out.println("" + numb);

Yeahhhhhh mannnnnn u did it!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

HAHAHA Thank you bro
Regards

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.