# ternary operator

partha karmakar
ternary operator
1 Answer(s)      4 years and a month ago
Posted in : Java Beginners

(Ternary operator)

Dearness Allowance= 25% of Basic pay house rent allowance= 15% of basic pay Provident fund= 8.33% of Basic pay Net pay=basic pay+Dearness allowance+house rent allowance Gross pay= Net pay-Provident fund

August 5, 2013 at 11:20 AM

Hi,

The ternary operator is used to simplify following type of code:

```boolean answer;
if ( a == b )
{
}
else
{
}

// You can write the above code in the following way
boolean answer =  a == b ? true : false;
```

Here is the complete code example of ternary operator in Java:

```public class  ternaryOperator
{
public static void main(String[] args)
{
System.out.println("Terniary Operator Example in Java");

int a=10;
int b=20;

if ( a == b )
{
}
else
{
}

// You can write the above code in the following way
answer =  a == b ? true : false;

System.out.println("Comparison Result: " + answer);

}
}
```

Thanks

Related Tutorials/Questions & Answers:
ternary operator
ternary operator  (Ternary operator) Dearness Allowance= 25% of Basic pay house rent allowance= 15% of basic pay Provident fund= 8.33% of Basic pay Net pay=basic pay+Dearness allowance+house rent allowance Gross pay= Net pay
Explain the ternary conditional operator in PHP?
Explain the ternary conditional operator in PHP?  Explain the ternary conditional operator in PHP
Java Questionmark operator
;  The only ternary (i.e. takes three values) operator in Java is the conditional operator.  Syntax: boolean-expression.... To know more about ternary operator http:/www.roseindia.net/java/master-java
AND operator in hibernate.
AND operator in hibernate.  How to use AND operator in hibernate
OR operator in hibernate.
OR operator in hibernate.  How to use OR operator in hibernate
What is the % operator?
What is the % operator?   Hi, What is the % operator? thanks
Java operator
Java operator  What are the legal operands of the instanceof operator
Java operator
Java operator  What is the difference between the prefix and postfix forms of the ++ operator
Java operator
Java operator  Which Java operator is right associative
like operator
like operator  how to select exact value using like operator in php
What is the difference between the Boolean & operator and the && operator?
What is the difference between the Boolean & operator and the && operator?   Hello, What is the difference between the Boolean & operator and the && operator? thanks
LIKE Operator
LIKE Operator       The LIKE operator is used for searching  a specified pattern in the column. In this example we will show you how to use the Like operator to get
SQL IN Operator
SQL IN Operator       SQL IN Operator helps you to specify multiple values in a WHERE Clause... IN Operator. In this example, we create a table 'Stu_Table'. The create
PHP Comparison Operator
be done by ternary operator (? :), in this operator we place the condition section...Comparison Operator: It is another kind of operator supported by PHP, with this operator you can compare two variables, whether the variables are equal
why we use ^ operator in sql, and what is the meaning of that operator?
why we use ^ operator in sql, and what is the meaning of that operator?  why we use ^ operator in sql, and what is the meaning of that operator
Java 'or' operator
Java 'or' operator       OR operator is a kind of a conditional operators, which... between the two boolean expressions. The OR operator (|) is similar
PHP Concatenation Operator
PHP Concatenation Operator  Hi friends, Can any one guide me how to use the concatenation string operator in PHP
Operator Precedence
Operator Precedence       Operator Precedence : In Java, Operator Precedence is an evaluation.... When two operators share an operand then operator with the higher precedence
cannot do the additional operator
and multiplication operator...please anyone help me <html> <head>... text field var operator = formCalculator.operator.value; //get input from first... declaration var output; // variable declaration // if else..if if (operator
SQL BETWEEN Operator
SQL BETWEEN Operator       The SQL Between Operator works where you want to select a range of data between two values. In SQL, the BETWEEN operator is used to select a range
What does the delete operator do?
What does the delete operator do?  What does the delete operator do
What does the delete operator do?
What does the delete operator do?  What does the delete operator do
javascript equality operator
javascript equality operator  javascript equality operator - What are the different ways to check the equality between strings?   javascript equality operator Equal (==) Not equal (!=) Strict equal
LIKE Operator
LIKE Operator       The LIKE operator is used for searching  a specified pattern in the column. In this example we will show you how to use the Like operator to get
Java "&" operator
Java "&" operator. In this section you will learn how to use "&" operator in java. Java provide six types of operators: among them one is Bitwise operator which can be applied to integer, long,  int
Simple Assignment Operator
Simple Assignment Operator       Assignment operator is the most common operator almost used with all programming languages
SQL IN Operator
SQL IN Operator       SQL IN Operator helps you to specify multiple values in a WHERE Clause... IN Operator. In this example, we create a table 'Stu_Table'. The create
Assignment operator in java
Assignment operator in java Assignment operator is very common to almost all... the value to the variable lying on the left side. Java assignment operator... to be assigned to the variable to the left side. Assignment operator is also used
How to use AND operator in hibernate Detached criteria query?
How to use AND operator in hibernate Detached criteria query?  How to use AND operator in hibernate Detached criteria query
Why does Java not support operator overloading?
Why does Java not support operator overloading?  Hi, Why does Java not support operator overloading? thanks