Results 1 to 4 of 4

Thread: digit spacing

  1. #1
    puk284 is offline Member
    Join Date
    Apr 2009
    Posts
    16
    Rep Power
    0

    Default [Solved]digit spacing

    Hi, im writing an application 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.
    Last edited by puk284; 06-09-2009 at 01:47 PM.

  2. #2
    Singing Boyo is offline Senior Member
    Join Date
    Mar 2009
    Posts
    552
    Rep Power
    6

    Default

    If you want 3 spaces between each digit, try something like this.

    Java Code:
    public String getSeparatedString(String separ){
         String spacing = "   "//three spaces     
         String ret = spacing;
         for(char c : separ.toCharArray()){
              ret += c + spacing;
         }
         return ret;
    }
    If you don't want spaces on the ends, just trim the string.
    If the above doesn't make sense to you, ignore it, but remember it - might be useful!
    And if you just randomly taught yourself to program, well... you're just like me!

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

    Default

    More information may help get a better answer. For instance, how are you getting the numbers and how are you displaying them? Is this a console application, or is this a Swing or other GUI? What have you tried so far, and can you show us the code?

    Best of luck.

  4. #4
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

    Default

    Quote Originally Posted by puk284 View Post
    The problem i have is that i want to separate the individual digits and display them separated by 3 spaces.
    I'm not clear with this. How can you do that with 3 spaces?

Similar Threads

  1. Locating a digit within a string
    By ScentOfAWookie in forum New To Java
    Replies: 8
    Last Post: 03-27-2009, 06:23 PM
  2. Problem with margins/spacing
    By joseche in forum AWT / Swing
    Replies: 2
    Last Post: 12-26-2008, 09:22 PM
  3. Spacing buttons on a panel
    By 2o2 in forum New To Java
    Replies: 8
    Last Post: 10-20-2008, 11:44 AM
  4. Java newb Q: 8-digit id
    By 1111FM in forum New To Java
    Replies: 2
    Last Post: 09-29-2008, 03:37 PM
  5. Help with spacing in java
    By barney in forum New To Java
    Replies: 1
    Last Post: 07-31-2007, 09:03 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
  •