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. HELP Please- Putting Digits within a number in ascending order

for example, if i am given 9864
i must output 4689

Without use of arrays.

2. Re: HELP Please- Putting Digits within a number in ascending order

there are many approach with that kind of problem.
The first approach that I thought is:
I have int var = 1; int answer = 0;
then I'll get the first digit, and multiply it by var.

next I'll multiply the var by 10, var now is 10
then I'll get the 2nd digit and multiply it by var, it will be 80 right?

next I'll multiply the var again by 10, var now is 100
then I'll get the 3rd digit and multiply it by var, it will be 600 right?

next I'll multiply the var again by 10, var now is 1000
then I'll get the 4th digit and multiply it by var, it will be 4000 right?