I need some help please !

I have a problem to solve in java. It goes like this : For a natural number n, find the maximum natural number m formed with the same digits. (example: n=3658, m=8653).

i have some part of it solved (i think) in C++ but i don't know how to change/finish it in java.

int x = 2574853;

int[] lx= new int[100];

int n = 0;

int aux = 0;

int y = 0;

while (x >0)

{

lx[n] = (int)x%10;

n++;

x = x/10;

}

for (int i= 0; i<n; i++)

for (int j= 0; j<n-1; j++)

if (lx[i] > lx[j])

{

aux = lx[i];

lx[i] = lx[j];

lx[j] = aux;

}

for (int i = 0; i < n; i++)

y = y * 10 + lx[i];

thank you in advance !!!