| | |
Need help with max/min'ing multiply
Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
•
•
Update: Now I get an error of ".class expected" for:
Java Syntax (Toggle Plain Text)
if(int input = 0);
You want to check the statement not assign value...
java Syntax (Toggle Plain Text)
if(input == 0){ // Then something }
Learn to see in another's calamity the ills which you should avoid.
Publilius Syrus
(~100 BC)
LJC - London Java Community, Graduate & Undergraduate Software Development Community, JAVAWUG (Java Web User Group), The London Android Group
Publilius Syrus
(~100 BC)
LJC - London Java Community, Graduate & Undergraduate Software Development Community, JAVAWUG (Java Web User Group), The London Android Group
•
•
•
•
Wrong answer, the if statement is wrong!
You want to check the statement not assign value...
java Syntax (Toggle Plain Text)
if(input == 0){ // Then something }
still, the ; shouldn't have been there
In my opinion this is a better way to do that, in looping you would have to customise the loop in a way that it runs only for set of values that you need for e.g. no repitition of the digits etc this way you would have to take care of a lot of conditions which would make the code complex. Hence I say that the method shown above would be a more cleaner convenient option.
Also since the repetition is not allowed you actually have lesser combination of digits to evaluate so that you can write out all the combinations by hand (which I guess won't be more than 4-6)
Also since the repetition is not allowed you actually have lesser combination of digits to evaluate so that you can write out all the combinations by hand (which I guess won't be more than 4-6)
Get up every morning and take a look at the Forbes' list of richest people. If your name doesn't appear.... GET TO WORK !!!
•
•
Join Date: Oct 2008
Posts: 37
Reputation:
Solved Threads: 0
Okay I'm kind of stuck on this if-else statement. I chose to just give the correct ones directly, since looping would be too difficult to fabricate. Right now I get an error "else without if" for:
Java Syntax (Toggle Plain Text)
if(input == 0){ { numOneLow = numOneTensLow + numOneOnesLow; numTwoLow = numTwoTensLow + numTwoOnesLow; numThreeLow = numThreeTensLow + numThreeOnesLow; System.out.println(lowproduct); } else(input == 1); numOneTensHigh + numOneOnesHigh; numTwoTensHigh + numTwoOnesHigh; numThreeTensHigh + numThreeOnesHigh; System.out.println(highproduct); }
Java Syntax (Toggle Plain Text)
if(input == 0){ {
remove one of the {'s
and also: re-check what you're doing here:
Java Syntax (Toggle Plain Text)
else(input == 1);
Last edited by stultuske; Dec 5th, 2008 at 9:50 am.
•
•
Join Date: Oct 2008
Posts: 37
Reputation:
Solved Threads: 0
Thanks for the help, and someone told me that I should use the (input == #); over what I had to eliminate an error. This was to read the input from the user to determine if they want to find the highest or lowest product. I'm going to revise this program completely this weekend so that it tests every possibility completely since I have no clue how I should fabricate it within a loop. If there were a way to switch the integers n1, n2, n3 with the initial tens value for either, I could use a loop; however, I'm new to java (more of a VB guy) and am unaware as to how to do such a thing. If I were to code it, it would end up being very unorthodox as most of my programs do.
yes and no.
yes: you do need to do if it are integers, since you want to compare the value to equality and they're not Objects.
no: you do not want to put the ';' straight after the if. what happens if what is between the brackets is true, is what is behind the if statement, until the first ';' if there are no '{ }'
so, if you would check it like that, and put the ';', you would automatically run the next lines, if the statement was true or not, since the next lines are not dependent on the if.
yes: you do need to do
Java Syntax (Toggle Plain Text)
if(input == valueToCheck)
no: you do not want to put the ';' straight after the if. what happens if what is between the brackets is true, is what is behind the if statement, until the first ';' if there are no '{ }'
so, if you would check it like that, and put the ';', you would automatically run the next lines, if the statement was true or not, since the next lines are not dependent on the if.
java Syntax (Toggle Plain Text)
if(input == 0){ { numOneLow = numOneTensLow + numOneOnesLow; numTwoLow = numTwoTensLow + numTwoOnesLow; numThreeLow = numThreeTensLow + numThreeOnesLow; System.out.println(lowproduct); } else(input == 1); numOneTensHigh + numOneOnesHigh; numTwoTensHigh + numTwoOnesHigh; numThreeTensHigh + numThreeOnesHigh; System.out.println(highproduct); }
I don't think this approach would always work.
E.g. 96*85*74 = 603840 whereas 76*85*94 = 607240 you will have to try out all possible combinations of them and then check for the maximum among them as shown by me in post #6
Get up every morning and take a look at the Forbes' list of richest people. If your name doesn't appear.... GET TO WORK !!!
•
•
•
•
java Syntax (Toggle Plain Text)
if(input == 0){ { ... } else(input == 1); ... }
I don't think this approach would always work.
![]() |
Other Threads in the Java Forum
- Previous Thread: Clock.java
- Next Thread: Netbeans:Importing existing code conundrum...
| Thread Tools | Search this Thread |
911 addball addressbook android api append applet application array arrays automation binary bluetooth button character chat class classes client code component consumer css csv database eclipse ee error event exception fractal ftp game givemetehcodez graphics gui html ide image input integer j2me japplet java javaarraylist javaprojects jmf jni jpanel julia jvm key linked linux list loan loop map method methods mobile netbeans newbie objects oriented output panel phone print printf problem program programming project projects recursion replaydirector reporting researchinmotion robot rotatetext scanner screen se server service set size sms software sort sql string swing test threads transfer tree ubuntu windows






