Welcome to the Java Programming Forums

The professional, friendly Java community. 21,500 members and growing!

The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.

>> REGISTER NOW TO START POSTING

1. Seperate numbers

So i've got a little proble with my code. The idea is to take a number for example 1234567890 and seperate its digits to : 1,2,3,4,5,6,7,8,9,0 or 0,9,8,7,6,5,4,3,2,1...For that a thought an algorithm but it doesnt work. Could u please check it!?!?!
```
package javaapplication16;

public class JavaApplication16 {
public static void main(String[] args) {
int x =1234567890;
int y;
for(int i = 1; i<10; i++){
y = x % 10^i/10^(i-1);
System.out.println(y);
}
}
}```

2. Re: Seperate numbers

Try separating the digits out one step at a time using the % and the / operators
instead of trying to do it all in one expression.

3. The Following User Says Thank You to Norm For This Useful Post:

nikomania (April 13th, 2013)

4. Re: Seperate numbers

Yes I tried that and it worked but the code then bacame quite big...But I dont understand why it doesnt work that way also!! Thanks anyway

5. Re: Seperate numbers

What does the code print out now?
I dont understand why it doesnt work that way
Try debugging the code by breaking that big expression up into single steps and print out the results at each step so you can see what the code is doing.

6. Re: Seperate numbers

As a side note:
```int x =1234567890;
for(int i = 1; i<10; i++)```
I can see that x is 10 digits, but the algorithm i see in my head would work for x with any number of digits

7. Re: Seperate numbers

If i do it step by step it prints 0 9 8 7 .... It works fine!