I want to use ? : expression instead of if with 4 conditions in this code but i dont know how< any answers please?
import java.util.Scanner;
public class Ex13 {
public static void main(String[] args) {
Scanner e = new Scanner(System.in);
int x, y, sum, diff;
boolean z = false;
System.out.println("Enter x and y");
x = e.nextInt();
y = e.nextInt();
sum = x+y;
diff = x-y;
if(x==15||y==15||sum==15||diff==15){
z=true;
}
System.out.println(z);
}}
i tried using else if else if, and i tried ? : but there was a problem with the lossy conversion from boolean to in types.
? :, or why the "lossy conversion"? And what "conversion from boolean to in"? (BTW the code could be simplified toz = x==15 || y==15 || sum==15 || diff==15;no need forifor? :- the expression/condition is already resulting in aboolean)