# ternary operator

Ads

Share on Google+

partha karmakar
ternary operator
1 Answer(s)      3 years and 9 months 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

Ads
View Answers

August 5, 2013 at 11:20 AM

Hi,

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

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

// 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;

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

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

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

}
}
```

Thanks

Ads

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
Advertisements
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
What is the % operator?
What is the % operator?   Hi, What is the % operator? thanks
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
Java operator
Java operator  Which Java operator is right associative
Java operator
Java operator  What is the difference between the prefix and postfix forms of the ++ operator
Java operator
Java operator  What are the legal operands of the instanceof operator
like operator
like operator  how to select exact value using like operator in php
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
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
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
c++ operator overloading
c++ operator overloading  What is operator overloading? and what is mean by overloading?? Can anyone please explain the concept in regards to C
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
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
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
PHP Concatenation Operator
PHP Concatenation Operator  Hi friends, Can any one guide me how to use the concatenation string operator in PHP
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
Simple Assignment Operator
Simple Assignment Operator       Assignment operator is the most common operator almost used with all programming languages
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
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
xor operator not working correctly with array
xor operator not working correctly with array  main { int a[2...",a[0],a[1]); }   hi friend, This is because the XOR operator is valid...;hi friend, This is because the XOR operator is valid for only two operands
Why does Java not support operator overloading?
Why does Java not support operator overloading?  Hi, Why does Java not support operator overloading? thanks
Tutorials

Ads

Advertisement null

Ads