View Single Post
Join Date: Oct 2008
Posts: 37
Reputation: IMtheBESTatJAVA has a little shameless behaviour in the past 
Solved Threads: 0
IMtheBESTatJAVA IMtheBESTatJAVA is offline Offline
Light Poster

Need help with max/min'ing multiply

 
0
  #1
Dec 1st, 2008
I've been given a project in which I have to find the highest and lowest possible product using 3 2-digit numbers without repeating any numbers.

For example, the algorithm for the highest would be:
7n * 8n * 9n where the n's would be 4, 5, or 6.
The algorithm for the lowest would be:
1n * 2n * 3n where the n's would be 4, 5, or 6.

So far, I know I will have to give an option of finding the lowest or highest, so I would ask the user to put in 0 to minimize and 1 to maximize. Now, I have thought of using an if statement for reading their input, but I need some kind of loop that will rearrange the 4's, 5's, or 6's. I thought of attaching the values of 4, 5, and 6 to the 90, 80, 70, or 10, 20, 30, but am unsure of how I would code a proper loop or simple if statement to find the best answer by trying each combination. In theory, I could make some really over-extensive amount of code to do it right, but it wouldn't follow curriculum.

The code I have so far is


  1. public class Powers
  2. {
  3. public static void main(String[] args);
  4.  
  5. int input;
  6. int numOneTensLow = 10;
  7. int numTwoTensLow = 20;
  8. int numThreeTensLow = 30;
  9. int numOneOnesLow = 4;
  10. int numTwoOnesLow = 5;
  11. int numThreeOnesLow = 6;
  12. int numOneTensHigh = 90;
  13. int numTwoTensHigh = 80;
  14. int numThreeTensHigh = 70;
  15. int numOneOnesHigh = 6;
  16. int numTwoOnesHigh = 5;
  17. int numThreeOnesHigh = 4;
  18. int numOneLow;
  19. int numTwoLow;
  20. int numThreeLow;
  21. int numOneHigh;
  22. int numTwoHigh;
  23. int numThreeHigh;
  24. int lowproduct = (numOneLow * numTwoLow * numThreeLow);
  25. int highprodcut = (numOneHigh * numTwoHigh * numThreeHigh);
  26.  
  27. ConsoleIO console = new ConsoleIO();
  28. System.out.println("This program will calculate three two-digit" +
  29. " numbers that create the lowest and highest possible products " +
  30. "using the numbers 1 through 9 once in each.");
  31. System.out.println("To calculate the highest input 1, to calculate" +
  32. " the lowest, input 0: ");
  33. input = console.readInt();
  34.  
  35. if(int input = 0);
  36. {
  37. do
  38. {
  39. numOneTensLow + NumOneOnesLow;
  40. numTwoTensLow + NumTwoOnesLow;
  41. numThreeTensLow + NumThreeOnesLow;
  42. System.out.println((numOneTensLow + numOneOnesLow) * (NumTwoTensLow + NumTwoOnesLow)
  43. * (NumThreeTensLow + NumThreeOnesLow));
  44. }
  45. }
Reply With Quote