Explain the ? operator in java, JAVA Programming

Assignment Help:

Explain The ?  operator in Java ?

The value of a variable frequent depends on whether a particular boolean expression is or is not true and on nothing else. For example one general operation is setting the value of a variable to the maximum of two quantities. In Java you might write

if (a > b) {
max = a;
}
else {
max = b;
}

Setting a single variable to one of two states based on a single condition is like a general use of if-else in which a shortcut has been devised for it, the conditional operator, ?:. By using the conditional operator you can rewrite the above instance in a single line such as this:

max = (a > b) ? a : b;

(a > b) ? a : b; is an expression that returns one of two values, a or b. The condition, (a > b), is tested. If it is true the first value, a, is returned. If it is false, the second value, b, is returned. Whenever value is returned is dependent on the conditional test, a > b. The condition can be any expression that returns a boolean value.


Related Discussions:- Explain the ? operator in java

On bluej, I need to write a program to assign values to the variable age an...

I need to write a program to assign values to the variable age and print the reason as major or minor.

What is white space explain proper use of white space java, What is White S...

What is White Space? explain proper use of white space in java? White space consists mainly of the space character in which you generates through hitting the space bar on your

How much cpu time does an applet get, How much CPU time does an applet get?...

How much CPU time does an applet get? One of the few legitimate concerns about hostile applets is excessive use of CPU time. It is possible on a non-preemptively multitasking s

What is synchronization, What is synchronization and why is it important? ...

What is synchronization and why is it important? With respect to multithreading, synchronization is the potential to control the access of multiple threads to shared resources.

Difference between durable and non-durable subscriptions, Point-To-Point (P...

Point-To-Point (PTP). This model permits exchanging messages via queues formed for some purposes. A client can send and receive messages from one or various queues. PTP model is ea

Sudoku class used in java program, Sudoku Class (Simple Version) The ...

Sudoku Class (Simple Version) The Sudoku class will encapsulate the minimum necessary data and logic to manipulate, print, and set the SudCells , in anticipation of a high

Describe remote objects?, Describe Remote Objects A Remote Object is o...

Describe Remote Objects A Remote Object is one whose functions can be called from another JVM. A remote object class must execute the Remote interface. A RMI Server is an appl

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd