View Single Post
Join Date: Nov 2008
Posts: 822
Reputation: verruckt24 is a jewel in the rough verruckt24 is a jewel in the rough verruckt24 is a jewel in the rough verruckt24 is a jewel in the rough 
Solved Threads: 73
verruckt24's Avatar
verruckt24 verruckt24 is offline Offline
Practically a Posting Shark

Re: Need help with max/min'ing multiply

 
0
  #6
Dec 2nd, 2008
I think you need to do something like this :
  1. highProduct1 = (numOneTensHigh + numOneOnesHigh) *
  2. (numTwoTensHigh + numTwoOnesHigh) *
  3. (numThreeTensHigh + numThreeOnesHigh);
  4.  
  5. highProduct2 = (numOneTensHigh + numTwoOnesHigh) *
  6. (numTwoTensHigh + numOneOnesHigh) *
  7. (numThreeTensHigh + numThreeOnesHigh);
  8.  
  9. highProduct3 = (numOneTensHigh + numThreeOnesHigh) *
  10. (numTwoTensHigh + numTwoOnesHigh) *
  11. (numThreeTensHigh + numOneOnesHigh);
  12.  
  13. highProduct4 = (numOneTensHigh + numOneOnesHigh) *
  14. (numTwoTensHigh + numThreeOnesHigh) *
  15. (numThreeTensHigh + numTwoOnesHigh);
  16.  
  17. // This way try all combinations, if there are left any others ;-)
  18. // then get the max of them.
  19.  
  20. if (max < highProduct1)
  21. max = highProduct1;
  22.  
  23. if (max < highProduct2)
  24. max = highProduct2;
  25.  
  26. if (max < highProduct3)
  27. max = highProduct3;
  28.  
  29. if (max < highProduct4)
  30. max = highProduct4;
  31.  
  32. // In the end print out the highest product
  33. System.out.println("Highest product is : " + max);

You can do the same way for the Lowest product.
Last edited by verruckt24; Dec 2nd, 2008 at 10:44 am.
Reply With Quote