DZone Forums
Go Back   DZone Forums > Community > Languages & Frameworks > Java
Reload this Page Separate a five digit number into parts.
Notices
Reply
 
LinkBack Thread Tools Display Modes
  (#1 (permalink)) Old
Member
 
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Join Date: Feb 2008
Default Separate a five digit number into parts. - 06-25-2008, 02:53 PM

Suppose i have a five digit number. How can i convert this number so that this number is divided into five parts and then separated by three blank spaces.
Suppose i have a number 12345 then i want output like that 1 2 3 4 5
Reply With Quote
  (#2 (permalink)) Old
Member
 
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Join Date: Jun 2008
Default 07-11-2008, 07:40 AM

Is this kind of a solution u are expecting ???

public static void main( String[] args )
{
String s = "12345";
String result = "";

for ( int i = 0; i < s.length(); i++ )
{
if ( result.length() > 0 )
{
result += " ";
}
result += ( s.charAt( i ) );

}
System.out.println( "Result is =>>> " + result );
}
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Maximum number of fields in a db2 PK?? balteo IBM DB2 3 08-08-2009 05:11 PM
customizing line number stellale Eclipse 0 12-14-2008 10:35 AM
TableViewer with dynamic number of columns danielmei Eclipse 1 09-16-2008 08:22 PM


Copyright 1997-2009, DZone, Inc.
vBulletin Skin developed by: vBStyles.com