posted 10 years ago

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.

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.

posted 10 years ago

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?

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.

Don't get me started about those stupid light bulbs. |