Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 09-30-2008, 08:05 PM
Member
 
Join Date: Sep 2008
Posts: 2
Rep Power: 0
Bangtajra123 is on a distinguished road
Default Problems with this Java Program...
If I prompt the user to enter a 5 digit number (ex. 12345) how do I separate those numbers by three spaces? (ex. 1 2 3 4 5) and print them back to the user? I don't want to use loops for this though, can anyone help me? I've been stuck on this forever and I can't figure it out....I've gotten as far as showing the 5 by itself but I can't figure out the rest....

I've been using Modulus but I can't figure out how to make it work after I get the 5 by itself. Can anyone help please? Thanks.
Bookmark Post in Technorati
Reply With Quote
  #2 (permalink)  
Old 09-30-2008, 08:24 PM
Nicholas Jordan's Avatar
Senior Member
 
Join Date: Jun 2008
Location: Southwest
Posts: 1,018
Rep Power: 3
Nicholas Jordan is on a distinguished road
Default kiss
Originally Posted by Bangtajra123 View Post
If I prompt the user to enter a 5 digit number (ex. 12345) how do I separate those numbers by three spaces? (ex. 1 2 3 4 5) and print them back to the user? I don't want to use loops for this though, can anyone help me? I've been stuck on this forever and I can't figure it out....I've gotten as far as showing the 5 by itself but I can't figure out the rest....
How did you do that?...

Originally Posted by Bangtajra123 View Post
I've been using Modulus but I can't figure out how to make it work after I get the 5 by itself. Can anyone help please? Thanks.
String temporaryString = new String(number.toString());
do
{
........

There is not much any way to do it except with loops unless you have an army of users who are only the lonely and all they have to do all day long is sit there and type:
"1...2....3....4....5"
"1...2....3....4....5"
"1...2....3....4....5"
"1...2....3....4....5"
"1...2....3....4....5"

Not much good for doing real comptuer science in the real world.
__________________
Introduction to Programming Using Java.
Cybercartography: A new theoretical construct proposed by D.R. Fraser Taylor
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 09-30-2008, 08:27 PM
Member
 
Join Date: Sep 2008
Posts: 2
Rep Power: 0
Bangtajra123 is on a distinguished road
Default
Yeah but is there a way where I can do it with JUST modulus? I've tried everything and I still can't figure it out, I've been on it forever.....arghhhh haha
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 09-30-2008, 09:13 PM
Fubarable's Avatar
Moderator
 
Join Date: Jun 2008
Posts: 6,391
Rep Power: 8
Fubarable is on a distinguished road
Default
What do you mean by doing this with modulus. It doesn't make sense to me, though this could be just my problem. If you don't get better answers soon, you may want to explain this more though.

Also, why the restriction on using for loops when they were made for this sort of thing? Is it a restriction of the assignment?

Also, if this is an assignment, are you allowed to use recursion?

Also, if this is an assignment, are you allowed to use other types of loops (while loops in particular)?

Last edited by Fubarable; 09-30-2008 at 09:18 PM.
Bookmark Post in Technorati
Reply With Quote
  #5 (permalink)  
Old 09-30-2008, 10:49 PM
Darryl.Burke's Avatar
Senior Member
 
Join Date: Sep 2008
Location: Madgaon, Goa, India
Posts: 716
Rep Power: 2
Darryl.Burke is on a distinguished road
Default
Code:
System.out.println("12345".replaceAll("(\\d)(?=\\d)", "$1   "));
Bookmark Post in Technorati
Reply With Quote
  #6 (permalink)  
Old 09-30-2008, 11:02 PM
Fubarable's Avatar
Moderator
 
Join Date: Jun 2008
Posts: 6,391
Rep Power: 8
Fubarable is on a distinguished road
Wink
Originally Posted by Darryl.Burke View Post
Code:
System.out.println("12345".replaceAll("(\\d)(?=\\d)", "$1   "));
You really are getting into the regular expressions. But you forgot to use modulus here (whatever that requirement means).
Bookmark Post in Technorati
Reply With Quote
  #7 (permalink)  
Old 09-30-2008, 11:04 PM
Norm's Avatar
Senior Member
 
Join Date: Jun 2008
Location: SouthWest Missouri, USA
Posts: 2,229
Rep Power: 4
Norm is on a distinguished road
Default
Is this a string manipulation problem or a number computation problem?
Darryl has given you the string solution.
Your wanting to use modulus implies that its a numeric problem.
For a numeric solution you want to find the number of 10000s, the number of 1000s, 100s, 10s and 1s. You could use division to find this.
modulus finds the remainder after the division.
Bookmark Post in Technorati
Reply With Quote
Reply

Bookmarks

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 On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Please help me solve these Java Problems saculellav New To Java 7 07-27-2008 12:58 PM
How to execute an External Program through Java program Java Tip java.io 0 04-04-2008 03:40 PM
Inventory part 3 program problems badness New To Java 1 12-17-2007 08:00 AM
External Program execution problems vital101 Advanced Java 3 10-30-2007 06:17 PM
How to execute an External Program through Java program JavaBean Java Tips 0 10-04-2007 10:33 PM


All times are GMT +2. The time now is 06:37 AM.



VBulletin, Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2009, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org