DaniWeb IT Discussion Community

DaniWeb IT Discussion Community (http://www.daniweb.com/forums/index.php)
-   Java (http://www.daniweb.com/forums/forum9.html)
-   -   Need help with max/min'ing multiply (http://www.daniweb.com/forums/thread160253.html)

peter_budo Dec 3rd, 2008 10:11 am
Re: Need help with max/min'ing multiply
 
Quote:

Originally Posted by IMtheBESTatJAVA (Post 749395)
Update: Now I get an error of ".class expected" for:
if(int input = 0);

Quote:

Originally Posted by stultuske (Post 749402)
that's to be expected, remove the ;

Wrong answer, the if statement is wrong!
You want to check the statement not assign value...
if(input == 0){
    // Then something
}

stultuske Dec 3rd, 2008 10:26 am
Re: Need help with max/min'ing multiply
 
Quote:

Originally Posted by peter_budo (Post 749428)
Wrong answer, the if statement is wrong!
You want to check the statement not assign value...
if(input == 0){
    // Then something
}

hmmmm ... must be even more tired than I thought to miss that :/
still, the ; shouldn't have been there

verruckt24 Dec 3rd, 2008 11:54 am
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)

IMtheBESTatJAVA Dec 5th, 2008 9:37 am
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:

        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);           
            }

stultuske Dec 5th, 2008 9:49 am
Re: Need help with max/min'ing multiply
 
 if(input == 0){
        {

remove one of the {'s

and also: re-check what you're doing here:
else(input == 1);

IMtheBESTatJAVA Dec 5th, 2008 3:03 pm
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.

stultuske Dec 6th, 2008 11:34 am
Re: Need help with max/min'ing multiply
 
Quote:

Originally Posted by IMtheBESTatJAVA (Post 751117)
(input == #);

yes and no.
yes: you do need to do
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.

verruckt24 Dec 8th, 2008 1:31 am
Re: Need help with max/min'ing multiply
 
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

stultuske Dec 8th, 2008 4:41 am
Re: Need help with max/min'ing multiply
 
Quote:

Originally Posted by verruckt24 (Post 752511)
if(input == 0){
        {
            ...
        }
        else(input == 1);
       
              ...           
            }

I don't think this approach would always work.

especially not if you copy the errors we pointed out a couple posts above ;) :)

verruckt24 Dec 8th, 2008 5:46 am
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.


All times are GMT -4. The time now is 7:03 am.

Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC