WAP to show the use of ternary operator.

1 year ago
OOP Java

Compile code:

public class Ternaryoperator  
{  
public static void main(String args[])   
{  
int x, y;  
x = 20;  
y = (x == 1) ? 61: 90;  
System.out.println("Value of y is: " +  y);  
y = (x == 20) ? 61: 90;  
System.out.println("Value of y is: " + y);  
}  
}

 

Output:

0
Dipti KC
Jan 8, 2023
More related questions

Questions Bank

View all Questions