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-Provident fund

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









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... of the operator. To know more about ternary operator http:/www.roseindia.net/java
ModuleNotFoundError: No module named 'ternary'
ModuleNotFoundError: No module named 'ternary'  Hi, My Python... 'ternary' How to remove the ModuleNotFoundError: No module named 'ternary... to install padas library. You can install ternary python with following command
ModuleNotFoundError: No module named 'ternary'
ModuleNotFoundError: No module named 'ternary'  Hi, My Python... 'ternary' How to remove the ModuleNotFoundError: No module named 'ternary... to install padas library. You can install ternary python with following command
ModuleNotFoundError: No module named 'python-ternary'
ModuleNotFoundError: No module named 'python-ternary'  Hi, My... named 'python-ternary' How to remove the ModuleNotFoundError: No module named 'python-ternary' error? Thanks   Hi, In your python
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... an example from SQL IN Operator. In this example, we create a table 'Stu
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
PHP Comparison Operator
of comparison could be done by ternary operator (? :), in this operator we place...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.... ADS_TO_REPLACE_1 When two operators share an operand then operator
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
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
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
ModuleNotFoundError: No module named 'ldh-operator'
ModuleNotFoundError: No module named 'ldh-operator'  Hi, My Python... 'ldh-operator' How to remove the ModuleNotFoundError: No module named 'ldh-operator' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'ldh-operator'
ModuleNotFoundError: No module named 'ldh-operator'  Hi, My Python... 'ldh-operator' How to remove the ModuleNotFoundError: No module named 'ldh-operator' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'micropython-operator'
ModuleNotFoundError: No module named 'micropython-operator'  Hi...: No module named 'micropython-operator' How to remove the ModuleNotFoundError: No module named 'micropython-operator' error? Thanks   Hi
ModuleNotFoundError: No module named 'operator-courier'
ModuleNotFoundError: No module named 'operator-courier'  Hi, My... named 'operator-courier' How to remove the ModuleNotFoundError: No module named 'operator-courier' error? Thanks   Hi, In your
ModuleNotFoundError: No module named 'pycopy-operator'
ModuleNotFoundError: No module named 'pycopy-operator'  Hi, My... named 'pycopy-operator' How to remove the ModuleNotFoundError: No module named 'pycopy-operator' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'remu-operator'
ModuleNotFoundError: No module named 'remu-operator'  Hi, My... 'remu-operator' How to remove the ModuleNotFoundError: No module named 'remu-operator' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'simple-operator'
ModuleNotFoundError: No module named 'simple-operator'  Hi, My... named 'simple-operator' How to remove the ModuleNotFoundError: No module named 'simple-operator' error? Thanks   Hi, In your python
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... an example from SQL IN Operator. In this example, we create a table 'Stu
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
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
xor operator not working correctly with array
xor operator not working correctly with array  main { int a[2] = {2,3}; printf("before swapping: %d %d\n",a[0],a[1]); //a[0] ^= a[1]; //a[1] ^= a[0]; //a[0] ^= a[1]; //this is working correctly. a[0] ^= a[1] ^= a[0
xor operator not working correctly with array
xor operator not working correctly with array  main { int a[2] = {2,3}; printf("before swapping: %d %d\n",a[0],a[1]); //a[0] ^= a[1]; //a[1] ^= a[0]; //a[0] ^= a[1]; //this is working correctly. a[0] ^= a[1] ^= a[0
ModuleNotFoundError: No module named 'dbnd-airflow-operator'
ModuleNotFoundError: No module named 'dbnd-airflow-operator'  Hi...: No module named 'dbnd-airflow-operator' How to remove the ModuleNotFoundError: No module named 'dbnd-airflow-operator' error? Thanks   Hi
ModuleNotFoundError: No module named 'py-enigma-operator'
ModuleNotFoundError: No module named 'py-enigma-operator'  Hi, My... named 'py-enigma-operator' How to remove the ModuleNotFoundError: No module named 'py-enigma-operator' error? Thanks   Hi, In your
ModuleNotFoundError: No module named 'dbnd-airflow-operator'
ModuleNotFoundError: No module named 'dbnd-airflow-operator'  Hi...: No module named 'dbnd-airflow-operator' How to remove the ModuleNotFoundError: No module named 'dbnd-airflow-operator' error? Thanks   Hi
ModuleNotFoundError: No module named 'flip-flop-operator'
ModuleNotFoundError: No module named 'flip-flop-operator'  Hi, My... named 'flip-flop-operator' How to remove the ModuleNotFoundError: No module named 'flip-flop-operator' error? Thanks   Hi, In your
ModuleNotFoundError: No module named 'ckan-cloud-operator'
ModuleNotFoundError: No module named 'ckan-cloud-operator'  Hi, My... named 'ckan-cloud-operator' How to remove the ModuleNotFoundError: No module named 'ckan-cloud-operator' error? Thanks   Hi
ModuleNotFoundError: No module named 'phone-operator-recognizer'
ModuleNotFoundError: No module named 'phone-operator-recognizer'  Hi...: No module named 'phone-operator-recognizer' How to remove the ModuleNotFoundError: No module named 'phone-operator-recognizer' error? Thanks  

Ads