# Seperate numbers

• April 13th, 2013, 08:47 AM
nikomania
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!?!?! :)
Code :

```  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); } } }```
• April 13th, 2013, 08:53 AM
Norm
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.
• April 13th, 2013, 08:57 AM
nikomania
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:)
• April 13th, 2013, 09:11 AM
Norm
Re: Seperate numbers
What does the code print out now?
Quote:

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.
• April 13th, 2013, 11:50 AM
jps
Re: Seperate numbers
As a side note:
Code :

```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
• April 13th, 2013, 12:15 PM
nikomania
Re: Seperate numbers
If i do it step by step it prints 0 9 8 7 .... It works fine!