# I need some help please !

Printable View

• 11-12-2010, 10:14 PM
gavroche
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 !!!
• 11-12-2010, 10:54 PM
pbrockway2
Quote:

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

Is that your code?

In any case the task is less one of changing or finishing and more one of starting. If you are required to write a program in Java, writing one in C++ was a misstep.

So, figure out quite precisely what you are going to do. (based on what your C++ is doing possibly) The important thing is that you are clear, and can clearly describe, each step in the process. Then start writing some code: one step at a time compiling often to deal with any problems as they arise.

There is plenty of opportunity to get help here, but you have to say what your problem is! As in what (the precise steps) you are trying to do, whatcode (Java) code you have written and what compiler messages or runtime behaviour you can't understand.

Good luck.
• 11-12-2010, 11:20 PM
gavroche
thank you for answering :)

the problem is that i don't know how to resolve it (and i'm sure it's simple), i wrote the problems requirements at the beginning (the c++ attempt was not made by me), so i'm less than a newbie at this :(
• 11-13-2010, 02:34 AM
al_Marshy_1981
Quote:

Originally Posted by gavroche
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.

Can you do this mathematically on paper?
• 11-13-2010, 02:47 AM
pbrockway2
To try and see what the steps are that you'll need to code, try answering the following two questions:

(1) What is the largest number you can make from the digits of 62208?

(2) How did you figure that out?

It's unlikely that you'll be able to answer the second in sufficient detail to begin coding, but a start is a start!