I'm trying to translate an if and else condition into ternary, but conditions are compounded, ie I need to indicate more than one statement on the same line.
According to what I researched the same can be done using comma, but in the compiler it expects that they have more: and; I changed it according to the compiler's indication and it did not solve, I think it's something simple that I still can not find a suitable answer or fragments of answers that meet and this demand, follows the codes below.
class Fibonaci{
int calculaFibonaci(int n){
/*if(n==1){
fibonaci=1;
fibonaci2=0;
} else {
fibonaci += fibonaci2;
fibonaci2 = fibonaci- fibonaci2;
}
}*/
fibonaci = (n==1)? fibonaci=1, fibonaci2=0 : fibonaci+=fibonaci2, fibonaci2 = fibonaci - fibonaci2;
return fibonaci;
}
}
OBS: Inside the comment is the condition if
and else
that works perfectly.