| | |
Need help with max/min'ing multiply
![]() |
•
•
Join Date: Oct 2008
Posts: 37
Reputation:
Solved Threads: 0
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
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
Java Syntax (Toggle Plain Text)
public class Powers { public static void main(String[] args); int input; int numOneTensLow = 10; int numTwoTensLow = 20; int numThreeTensLow = 30; int numOneOnesLow = 4; int numTwoOnesLow = 5; int numThreeOnesLow = 6; int numOneTensHigh = 90; int numTwoTensHigh = 80; int numThreeTensHigh = 70; int numOneOnesHigh = 6; int numTwoOnesHigh = 5; int numThreeOnesHigh = 4; int numOneLow; int numTwoLow; int numThreeLow; int numOneHigh; int numTwoHigh; int numThreeHigh; int lowproduct = (numOneLow * numTwoLow * numThreeLow); int highprodcut = (numOneHigh * numTwoHigh * numThreeHigh); ConsoleIO console = new ConsoleIO(); System.out.println("This program will calculate three two-digit" + " numbers that create the lowest and highest possible products " + "using the numbers 1 through 9 once in each."); System.out.println("To calculate the highest input 1, to calculate" + " the lowest, input 0: "); input = console.readInt(); if(int input = 0); { do { numOneTensLow + NumOneOnesLow; numTwoTensLow + NumTwoOnesLow; numThreeTensLow + NumThreeOnesLow; System.out.println((numOneTensLow + numOneOnesLow) * (NumTwoTensLow + NumTwoOnesLow) * (NumThreeTensLow + NumThreeOnesLow)); } }
•
•
Join Date: Aug 2008
Posts: 1,160
Reputation:
Solved Threads: 137
would love to help you imbestatjava, but i have no clue what you are trying to do
multiply by numbers by products of 7,8,9 and 1,2,3?
that part is understandable, but what is this?
i don't get what these values have to do with anything
multiply by numbers by products of 7,8,9 and 1,2,3?
that part is understandable, but what is this?
•
•
•
•
90, 80, 70, or 10, 20, 30
Custom Application & Software Development
www.houseshark.net
www.houseshark.net
•
•
Join Date: Oct 2008
Posts: 37
Reputation:
Solved Threads: 0
The values 90, 80, 70 and 10, 20, 30 have a lot to do with the program because im trying to find the highest possible combination of 9n, 8n, and 7n so it'd be (90 + n) * (80 + n) * (70 + n) where every n must be either 4, 5, or 6. So far the only error I can actually see is in the line of code
Java Syntax (Toggle Plain Text)
public static void main(String[] args);
I think you need to do something like this :
You can do the same way for the Lowest product.
java Syntax (Toggle Plain Text)
highProduct1 = (numOneTensHigh + numOneOnesHigh) * (numTwoTensHigh + numTwoOnesHigh) * (numThreeTensHigh + numThreeOnesHigh); highProduct2 = (numOneTensHigh + numTwoOnesHigh) * (numTwoTensHigh + numOneOnesHigh) * (numThreeTensHigh + numThreeOnesHigh); highProduct3 = (numOneTensHigh + numThreeOnesHigh) * (numTwoTensHigh + numTwoOnesHigh) * (numThreeTensHigh + numOneOnesHigh); highProduct4 = (numOneTensHigh + numOneOnesHigh) * (numTwoTensHigh + numThreeOnesHigh) * (numThreeTensHigh + numTwoOnesHigh); // This way try all combinations, if there are left any others ;-) // then get the max of them. if (max < highProduct1) max = highProduct1; if (max < highProduct2) max = highProduct2; if (max < highProduct3) max = highProduct3; if (max < highProduct4) max = highProduct4; // In the end print out the highest product 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.
•
•
Join Date: Nov 2008
Posts: 332
Reputation:
Solved Threads: 53
Your theme posted here is interesting. Min/max, combinatoric algorithms.
Line
Add
Download from http://www.netbeans.org/ NetBans IDE 6.5, select Java SE 37 MB.
and Java SE Development Kit (JDK) 6 Update 11 from http://java.sun.com/javase/downloads/index.jsp ,
or
JDK 6 Update 11 with NetBeans 6.5 from http://java.sun.com/javase/downloads/index.jsp .
It's free.
Install and work.
Advanced editor show to You all wrong points in code before compiling.
Line
public static void main(String[] args); change topublic static void main(String[] args){ Add
}} at end of program.Download from http://www.netbeans.org/ NetBans IDE 6.5, select Java SE 37 MB.
and Java SE Development Kit (JDK) 6 Update 11 from http://java.sun.com/javase/downloads/index.jsp ,
or
JDK 6 Update 11 with NetBeans 6.5 from http://java.sun.com/javase/downloads/index.jsp .
It's free.
Install and work.
Advanced editor show to You all wrong points in code before compiling.
•
•
Join Date: Oct 2008
Posts: 37
Reputation:
Solved Threads: 0
I'm supposed to use BlueJ and its supposed to be a three-way multiplication, so I was hoping there could be some kind of loop I could use for this. An example for the maximization would be:
(90 + 6) * (80 + 5) * (70 +4)
And minimization would look like:
(10 + 5) * (20 + 6) * (30 + 4)
And somehow in a loop I would have to try each combination, so if I were to do each individually it would look like a bunch of lines of this:
14 * 25 * 36
14 * 26 * 35
15 * 26 * 34
15 * 24 * 36
16 * 25 * 34
16 * 24 * 35
...and that's just minimization.
Update: Now I get an error of ".class expected" for:
(90 + 6) * (80 + 5) * (70 +4)
And minimization would look like:
(10 + 5) * (20 + 6) * (30 + 4)
And somehow in a loop I would have to try each combination, so if I were to do each individually it would look like a bunch of lines of this:
14 * 25 * 36
14 * 26 * 35
15 * 26 * 34
15 * 24 * 36
16 * 25 * 34
16 * 24 * 35
...and that's just minimization.
Update: Now I get an error of ".class expected" for:
Java Syntax (Toggle Plain Text)
if(int input = 0);
Last edited by IMtheBESTatJAVA; Dec 3rd, 2008 at 9:10 am.
•
•
•
•
Update: Now I get an error of ".class expected" for:
Java Syntax (Toggle Plain Text)
if(int input = 0);
![]() |
Other Threads in the Java Forum
- Previous Thread: Clock.java
- Next Thread: Netbeans:Importing existing code conundrum...
| Thread Tools | Search this Thread |
android api applet application apps array arrays automation awt bidirectional binary birt bluetooth businessintelligence busy_handler(null) card chat class classes client code collision columns component constructor crashcourse database designadrawingapplicationusingjavajslider draw eclipse error errors eventlistener exception expand fractal game givemetehcodez graphics gui guidancer html ide image inetaddress integer intellij j2me java javafx javamicroeditionuseofmotionsensor javaprojects jme jni jpanel jtree julia linux list loop machine map method methods mobile mobiledevelopmentcreatejar myaggfun netbeans newbie oracle physics plazmic print problem program programming project recursion scanner server set sharepoint smart sms smsspam sort sortedmaps sql string subclass support swing textfield threads tree trolltech unlimited utility webservices windows






