how can i set a boolean to put in an if else statement with the following code
if((Math.abs(x)==1)&&(Math.abs(ex)==1)&&(Math.abs(exx)==2))//test for straight
System.out.print("Straight");

if((cardSuit==0)&&(cardSuit2==0)&&(cardSuit3==0))//test for flush
System.out.print(" Flush ");


i want to set a boolean straight and boolean flush to put in another if else statement like so

if(straight && flush)
System.out.println("Good Game");

P.S. how can i check off that a thread is solved
i appreciate the help

Recommended Answers

All 6 Replies

Which world are you from, If you are not aware then "if" statements can be multiline too.
For ex :

if(.........) {
    a = true;
    b= false;
    .
    .
    .
}  else if (........) {
    a = false;
    b = true;
    .
    .
    .
    .
    .
} else {
    .
    .
    .
}

You can read more about it here

And please wrap your code in [code=java] and [/code] tags. It keeps your post organized and clean rather than the garbage you can see above. Its a bit irritating that this is your eighth post and you have not yet even glanced at the forum rules.

sorry about that and thank you very much

im sorry but i dont understand it

sorry about the bad post above

i'm sorry but i still don't understand
i tried doing something like this:

if((Math.abs(x)==1)&&(Math.abs(ex)==1)&&(Math.abs(exx)==2))//test for straight
   {
        System.out.print("Straight");
        boolean straight = true;
        boolean straight2 = false;
    }

if((cardSuit==0)&&(cardSuit2==0)&&(cardSuit3==0))//test for flush
    {
        System.out.print(" Flush ");
        boolean flush = true;
        boolean flush2 = false;
    }
else if(straight&&flush)//test for royal straight flush
        System.out.println("Good Game ");

maybe im not making myself clear enough.
i want the test for straight and test for flush to be in one if-else statement. if not with a boolean, is there another way
i really need help quick

commented: Refusal to use code tags and repeated bumping of thread. -3
commented: made it very clear -1

maybe im not making myself clear enough

I understood the problem, it is you who are having trouble arriving at a solution.

i really need help quick

I am not in the same timezone as you, and honestly I need my sleep and if you still refuse to follow the rules dont expect too much help at least from me.

But one last time, you really need to learn Java, It also seems that you are not familiar with any of the languages from the C family. In that case I suggest you buy a good book for beginners mentioned in the Starting Java thread.

And as far as the new problem you have created with your program goes, it is related to scope of a variable.
A variable declared inside a block of code (inbetween { and }) cannot be accessed outside of it.
So you need to declare your flush,flush2, straight and straight2 variables out side and before the corresponding "if" blocks.

You can look for more information on scope of variables here and you can also try this example.

And please do not directly copy paste (without applying your thinking ability) the if template which I gave, it was just for illustrating how you can have multiple statements executing for an if condition. There is no need to initialise two booleans one true and other false for every if block.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.