• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Problem at the drawing board - ordering numbers.

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Ranch Hand
Posts: 1090
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
reply
    Bookmark Topic Watch Topic
  • New Topic