0

Hi, im writing an application in java 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.

4
Contributors
3
Replies
4
Views
8 Years
Discussion Span
Last Post by javaAddict
0

Hi, im writing an application in java 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.

You can use the / and % operators to isolate each digit. You should probably set up an array of five integers to hold the digits and set up a for-loop. Isolate one digit every trip through the for-loop.

0

Puk, You are lazy.

int n=12345;

        String s="";

        while(n>0)
           {
             s=n%10 + "   " + s;
             n=n/10;
           }

        System.out.println(s);
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.