Need help with max/min'ing multiply

Reply

Join Date: Dec 2004
Posts: 4,177
Reputation: peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of 
Solved Threads: 479
Moderator
Featured Poster
peter_budo's Avatar
peter_budo peter_budo is offline Offline
Code tags enforcer

Re: Need help with max/min'ing multiply

 
0
  #11
Dec 3rd, 2008
Originally Posted by IMtheBESTatJAVA View Post
Update: Now I get an error of ".class expected" for:
  1. if(int input = 0);
Originally Posted by stultuske View Post
that's to be expected, remove the ;
Wrong answer, the if statement is wrong!
You want to check the statement not assign value...
  1. if(input == 0){
  2. // Then something
  3. }
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
Reply With Quote Quick reply to this message  
Join Date: Jan 2007
Posts: 706
Reputation: stultuske is a jewel in the rough stultuske is a jewel in the rough stultuske is a jewel in the rough 
Solved Threads: 84
stultuske's Avatar
stultuske stultuske is offline Offline
Master Poster

Re: Need help with max/min'ing multiply

 
0
  #12
Dec 3rd, 2008
Originally Posted by peter_budo View Post
Wrong answer, the if statement is wrong!
You want to check the statement not assign value...
  1. if(input == 0){
  2. // Then something
  3. }
hmmmm ... must be even more tired than I thought to miss that :/
still, the ; shouldn't have been there
Reply With Quote Quick reply to this message  
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
  #13
Dec 3rd, 2008
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)
Get up every morning and take a look at the Forbes' list of richest people. If your name doesn't appear.... GET TO WORK !!!
Reply With Quote Quick reply to this message  
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

Re: Need help with max/min'ing multiply

 
0
  #14
Dec 5th, 2008
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:

  1. if(input == 0){
  2. {
  3. numOneLow = numOneTensLow + numOneOnesLow;
  4. numTwoLow = numTwoTensLow + numTwoOnesLow;
  5. numThreeLow = numThreeTensLow + numThreeOnesLow;
  6. System.out.println(lowproduct);
  7. }
  8. else(input == 1);
  9.  
  10. numOneTensHigh + numOneOnesHigh;
  11. numTwoTensHigh + numTwoOnesHigh;
  12. numThreeTensHigh + numThreeOnesHigh;
  13. System.out.println(highproduct);
  14. }
Reply With Quote Quick reply to this message  
Join Date: Jan 2007
Posts: 706
Reputation: stultuske is a jewel in the rough stultuske is a jewel in the rough stultuske is a jewel in the rough 
Solved Threads: 84
stultuske's Avatar
stultuske stultuske is offline Offline
Master Poster

Re: Need help with max/min'ing multiply

 
0
  #15
Dec 5th, 2008
  1. if(input == 0){
  2. {

remove one of the {'s

and also: re-check what you're doing here:
  1. else(input == 1);
Last edited by stultuske; Dec 5th, 2008 at 9:50 am.
Reply With Quote Quick reply to this message  
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

Re: Need help with max/min'ing multiply

 
0
  #16
Dec 5th, 2008
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.
Reply With Quote Quick reply to this message  
Join Date: Jan 2007
Posts: 706
Reputation: stultuske is a jewel in the rough stultuske is a jewel in the rough stultuske is a jewel in the rough 
Solved Threads: 84
stultuske's Avatar
stultuske stultuske is offline Offline
Master Poster

Re: Need help with max/min'ing multiply

 
0
  #17
Dec 6th, 2008
Originally Posted by IMtheBESTatJAVA View Post
(input == #);
yes and no.
yes: you do need to do
  1. if(input == valueToCheck)
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.
Reply With Quote Quick reply to this message  
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
  #18
Dec 8th, 2008
  1. if(input == 0){
  2. {
  3. numOneLow = numOneTensLow + numOneOnesLow;
  4. numTwoLow = numTwoTensLow + numTwoOnesLow;
  5. numThreeLow = numThreeTensLow + numThreeOnesLow;
  6. System.out.println(lowproduct);
  7. }
  8. else(input == 1);
  9.  
  10. numOneTensHigh + numOneOnesHigh;
  11. numTwoTensHigh + numTwoOnesHigh;
  12. numThreeTensHigh + numThreeOnesHigh;
  13. System.out.println(highproduct);
  14. }

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 !!!
Reply With Quote Quick reply to this message  
Join Date: Jan 2007
Posts: 706
Reputation: stultuske is a jewel in the rough stultuske is a jewel in the rough stultuske is a jewel in the rough 
Solved Threads: 84
stultuske's Avatar
stultuske stultuske is offline Offline
Master Poster

Re: Need help with max/min'ing multiply

 
0
  #19
Dec 8th, 2008
Originally Posted by verruckt24 View Post
  1. if(input == 0){
  2. {
  3. ...
  4. }
  5. else(input == 1);
  6.  
  7. ...
  8. }

I don't think this approach would always work.
especially not if you copy the errors we pointed out a couple posts above
Reply With Quote Quick reply to this message  
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
  #20
Dec 8th, 2008
thats for him to remove, I just copied the code he has pasted a couple posts above in the thread. Its certainly not my job.
Get up every morning and take a look at the Forbes' list of richest people. If your name doesn't appear.... GET TO WORK !!!
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the Java Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC