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

Explain about drawing lines, Explain about Drawing Lines? Drawing strai...

Explain about Drawing Lines? Drawing straight lines along with Java is easy. Just call g.drawLine(x1, y1, x2, y2) where (x1, y1) and (x2, y2) are the endpoints of your lines

How jms is different from rpc, In RPC the method invoker waits for the meth...

In RPC the method invoker waits for the method to finish implementation and return the control back to the invoker. Therefore it is completely synchronous in nature. Whereas in JMS

What is an advice, Advice is the execution of an aspect. It is something li...

Advice is the execution of an aspect. It is something like telling your application of a new behavior. Generally, and advice is inserted into an application at joinpoints

What is the use of textmessage, TextMessage having instance of java.lang.St...

TextMessage having instance of java.lang.String as its payload. Therefore it is very useful for exchanging textual data. It can also be used for exchanging difficult character data

Inheritances and interfaces, #queThis assignment will give you practice wit...

#queThis assignment will give you practice with defining classes. You are to write a set of classes that define the behavior of certain animals. You will be given a program that r

Oop, creating a point of sale

creating a point of sale

Describe the concept of encapsulation, Describe the concept of Encapsulatio...

Describe the concept of Encapsulation  Encapsulation is a technique which is used for hiding properties and behaviors of an object and allowing outside access only as appropria

Non-final functions in java object class, Normal 0 false fals...

Normal 0 false false false EN-US X-NONE X-NONE

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