0% found this document useful (0 votes)
51 views

Misc Operators

The conditional operator, also known as the ternary operator, is used to evaluate boolean expressions and decide which value should be assigned to a variable. It consists of three operands and is written as "variable x = (expression) ? value if true : value if false". For example, it can check if a variable is equal to 1 or 10 and assign the variable b either the value 20 or 30 depending on the expression result.

Uploaded by

crazz1
Copyright
© © All Rights Reserved
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
51 views

Misc Operators

The conditional operator, also known as the ternary operator, is used to evaluate boolean expressions and decide which value should be assigned to a variable. It consists of three operands and is written as "variable x = (expression) ? value if true : value if false". For example, it can check if a variable is equal to 1 or 10 and assign the variable b either the value 20 or 30 depending on the expression result.

Uploaded by

crazz1
Copyright
© © All Rights Reserved
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 1

Misc Operators

There are few other operators supported by Java Language.

Conditional Operator ( ? : ):

Conditional operator is also known as the ternary operator. This


operator consists of
three operands and is used to evaluate Boolean expressions.
The goal of the operator is
to decide which value should be assigned to the variable. The
operator is written as:
variable x = (expression) ? value if true : value if false

Following is the example:

public class Test {


public static void main(String args[]){
int a , b;
a = 10;
b = (a == 1) ? 20: 30;
System.out.println( "Value of b is : " + b );
b = (a == 10) ? 20: 30;
System.out.println( "Value of b is : " + b );
}
}

This would produce the following result:


Value of b is : 30
Value of b is : 20

You might also like