943,721 Members | Top Members by Rank

Ad:
  • Java Discussion Thread
  • Unsolved
  • Views: 2285
  • Java RSS
You are currently viewing page 2 of this multi-page discussion thread; Jump to the first page
Dec 3rd, 2008
0

Re: Need help with max/min'ing multiply

Update: Now I get an error of ".class expected" for:
Java Syntax (Toggle Plain Text)
  1. if(int input = 0);
Click to Expand / Collapse  Quote originally posted by stultuske ...
that's to be expected, remove the ;
Wrong answer, the if statement is wrong!
You want to check the statement not assign value...
java Syntax (Toggle Plain Text)
  1. if(input == 0){
  2. // Then something
  3. }
Moderator
Featured Poster
Reputation Points: 2786
Solved Threads: 871
Code tags enforcer
peter_budo is offline Offline
6,656 posts
since Dec 2004
Dec 3rd, 2008
0

Re: Need help with max/min'ing multiply

Click to Expand / Collapse  Quote originally posted by peter_budo ...
Wrong answer, the if statement is wrong!
You want to check the statement not assign value...
java Syntax (Toggle Plain Text)
  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
Reputation Points: 919
Solved Threads: 354
Nearly a Posting Maven
stultuske is offline Offline
2,487 posts
since Jan 2007
Dec 3rd, 2008
0

Re: Need help with max/min'ing multiply

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)
Reputation Points: 485
Solved Threads: 89
Posting Shark
verruckt24 is offline Offline
944 posts
since Nov 2008
Dec 5th, 2008
0

Re: Need help with max/min'ing multiply

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)
  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. }
Reputation Points: -1
Solved Threads: 0
Light Poster
IMtheBESTatJAVA is offline Offline
36 posts
since Oct 2008
Dec 5th, 2008
0

Re: Need help with max/min'ing multiply

Java Syntax (Toggle Plain Text)
  1. if(input == 0){
  2. {

remove one of the {'s

and also: re-check what you're doing here:
Java Syntax (Toggle Plain Text)
  1. else(input == 1);
Last edited by stultuske; Dec 5th, 2008 at 9:50 am.
Reputation Points: 919
Solved Threads: 354
Nearly a Posting Maven
stultuske is offline Offline
2,487 posts
since Jan 2007
Dec 5th, 2008
0

Re: Need help with max/min'ing multiply

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.
Reputation Points: -1
Solved Threads: 0
Light Poster
IMtheBESTatJAVA is offline Offline
36 posts
since Oct 2008
Dec 6th, 2008
0

Re: Need help with max/min'ing multiply

(input == #);
yes and no.
yes: you do need to do
Java Syntax (Toggle Plain Text)
  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.
Reputation Points: 919
Solved Threads: 354
Nearly a Posting Maven
stultuske is offline Offline
2,487 posts
since Jan 2007
Dec 8th, 2008
0

Re: Need help with max/min'ing multiply

java Syntax (Toggle Plain Text)
  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
Reputation Points: 485
Solved Threads: 89
Posting Shark
verruckt24 is offline Offline
944 posts
since Nov 2008
Dec 8th, 2008
0

Re: Need help with max/min'ing multiply

Click to Expand / Collapse  Quote originally posted by verruckt24 ...
java Syntax (Toggle Plain Text)
  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
Reputation Points: 919
Solved Threads: 354
Nearly a Posting Maven
stultuske is offline Offline
2,487 posts
since Jan 2007
Dec 8th, 2008
0

Re: Need help with max/min'ing multiply

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.
Reputation Points: 485
Solved Threads: 89
Posting Shark
verruckt24 is offline Offline
944 posts
since Nov 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Java Forum Timeline: Clock.java
Next Thread in Java Forum Timeline: Netbeans:Importing existing code conundrum...





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC