aspose file tools*
The moose likes Beginning Java and the fly likes Problem at the drawing board - ordering numbers. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Problem at the drawing board - ordering numbers." Watch "Problem at the drawing board - ordering numbers." New topic
Author

Problem at the drawing board - ordering numbers.

ShaunRobert Williams
Greenhorn

Joined: Apr 19, 2007
Posts: 3
All,

Ive been trying to get into the programming grove with java, but wasnt having much opertunity to practise what Ive learnt, and then I thought I had found the perfect solution - The uni of auckland posts assignments from previous years on its website. I thought if I could do these, ill get plenty of the right kinda practise, i mean, these guys teach people how to code for a living, right?

One small problem, and its not with Java per se.

Im stuck trying to figure the algorythm for the 3rd (yes, the 3rd) excerise.

It sounds simple enough. Given 3 numbers, put them in order, smallest to bigest.
Just one complication: no conditional statements of any kind. Use on Math.max() and Math.min().

Now, im sure its possible, but I cant figure it. Neither can the various members of the family ive posed it as a simple puzzle too. Ive spend a good 2 hours on this away from the computer with 3 cards and a notebook.

I think I got finding the smallest and biggest, like this:



But, whatever i do, it seems without conditional statments (which I take to be if, while, and for)
I can not get the middle number.

Im sure its possible, probley very obvious, but the way my brain is wired, I can't figure.

Any pointers, tips and/or peusdocode would enable me to sleep tonight.
Thanks.
Joe Wolfe
Ranch Hand

Joined: Apr 25, 2007
Posts: 87
I guess nested function or methods

int maximum = Math.max(n1, Math.max(n2,n3)); or something similar.

There could be some neat OO way to do it too. not sure.

Most college textbooks have problems sets at the end of the chapters along with solutions for the odd or even exercises on the CDs. I suggest these.

This sounds like a trivial exercise for a college course?


If not now then never.
Anupam Sinha
Ranch Hand

Joined: Apr 13, 2003
Posts: 1088
Now that you have the max and the min number. Add all the three orignal numbers together. Then subtract the sum of the maximum and the minimum from the sum of the three numbers.
[ May 08, 2007: Message edited by: Anupam Sinha ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Problem at the drawing board - ordering numbers.