Hi, im writing an application in java that collects a number consisting of 5 digits,for example, 11234 from the user. The problem i have is that i want to separate the individual digits and display them separated by 3 spaces. thank you in advance for your help.
You can use the / and % operators to isolate each digit. You should probably set up an array of five integers to hold the digits and set up a for-loop. Isolate one digit every trip through the for-loop.
VernonDozier
Posting Expert
5,527 posts since Jan 2008
Reputation Points: 2,633
Solved Threads: 711
Puk, You are lazy.
int n=12345;
String s="";
while(n>0)
{
s=n%10 + " " + s;
n=n/10;
}
System.out.println(s);
__avd
Posting Genius (adatapost)
8,648 posts since Oct 2008
Reputation Points: 2,136
Solved Threads: 1,241
You can try the .charAt() method of String class
javaAddict
Nearly a Senior Poster
3,329 posts since Dec 2007
Reputation Points: 1,014
Solved Threads: 448