Combine more than one condition in an if

1

Is it possible to combine more than one condition in the tire industry? Example:

boolean existe = pessoa tem 23 ou pessoa tem 22 ? true : false ;

I'm trying but I can not.

    
asked by anonymous 24.03.2017 / 19:03

2 answers

8

Would that be?

boolean existe = (idade == 22 || idade == 23);
    
24.03.2017 / 19:06
-2

Yes, it is possible:

If you want to necessarily use the ternary operator (as asked):

boolean existe = pessoa.getIdade() == 23? true : pessoa.getIdade() == 22? true : false ;

But in this example you would not need to use this operator:

boolean existe = pessoa.getIdade() == 23 || pessoa.getIdade() == 22;
    
25.03.2017 / 14:15