D
D
Denis Plus2019-04-15 08:49:10
Java
Denis Plus, 2019-04-15 08:49:10

How to replace such an if-else construct with a ternary operator?

int a = 10;
int b;
       // b = a > 0 ? (a < 100 ? b = 1 : b = 0): b = -1;
if (a > 0) {
   if (a < 100) {
       b = 1;
   } else {
       b = 0;
 };
 } 
else {
     b = -1;
 }

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Evgeny Samsonov, 2019-04-15
@nikstormr

int b = a > 0 ? (a < 100 ? 1 : 0): -1;

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question