Results 1 to 7 of 7
  1. #1
    Bangtajra123 is offline Member
    Join Date
    Sep 2008
    Posts
    2
    Rep Power
    0

    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.

  2. #2
    Nicholas Jordan's Avatar
    Nicholas Jordan is offline Senior Member
    Join Date
    Jun 2008
    Location
    Southwest
    Posts
    1,018
    Rep Power
    8

    Default kiss

    Quote 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?...

    Quote 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

  3. #3
    Bangtajra123 is offline Member
    Join Date
    Sep 2008
    Posts
    2
    Rep Power
    0

    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

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    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 08:18 PM.

  5. #5
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,423
    Rep Power
    20

    Default

    Java Code:
    System.out.println("12345".replaceAll("(\\d)(?=\\d)", "$1   "));

  6. #6
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Wink

    Quote Originally Posted by Darryl.Burke View Post
    Java 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). ;)

  7. #7
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,572
    Rep Power
    25

    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.

Similar Threads

  1. Please help me solve these Java Problems
    By saculellav in forum New To Java
    Replies: 9
    Last Post: 07-06-2014, 09:25 AM
  2. Replies: 0
    Last Post: 04-04-2008, 02:40 PM
  3. Inventory part 3 program problems
    By badness in forum New To Java
    Replies: 1
    Last Post: 12-17-2007, 07:00 AM
  4. External Program execution problems
    By vital101 in forum Advanced Java
    Replies: 3
    Last Post: 10-30-2007, 05:17 PM
  5. Replies: 0
    Last Post: 10-04-2007, 09:33 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •