Results 1 to 7 of 7
- 09-30-2008, 07:05 PM #1
Member
- Join Date
- Sep 2008
- Posts
- 2
- Rep Power
- 0
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.
- 09-30-2008, 07:24 PM #2
kiss
How did you do that?...
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
- 09-30-2008, 07:27 PM #3
Member
- Join Date
- Sep 2008
- Posts
- 2
- Rep Power
- 0
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
-
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 08:18 PM.
- 09-30-2008, 09:49 PM #5
Java Code:System.out.println("12345".replaceAll("(\\d)(?=\\d)", "$1 "));
-
- 09-30-2008, 10:04 PM #7
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.
Similar Threads
-
Please help me solve these Java Problems
By saculellav in forum New To JavaReplies: 7Last Post: 07-27-2008, 11:58 AM -
How to execute an External Program through Java program
By Java Tip in forum java.ioReplies: 0Last Post: 04-04-2008, 02:40 PM -
Inventory part 3 program problems
By badness in forum New To JavaReplies: 1Last Post: 12-17-2007, 07:00 AM -
External Program execution problems
By vital101 in forum Advanced JavaReplies: 3Last Post: 10-30-2007, 05:17 PM -
How to execute an External Program through Java program
By JavaBean in forum Java TipReplies: 0Last Post: 10-04-2007, 09:33 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks