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

List down the analytical engine''s elements name, List down the Analytical ...

List down the Analytical Engine's elements name An analytical engine elements are as follows: Input Memory Processor Output.

Why hub is used in networks, Why hub is used in networks? HUB: Hub is n...

Why hub is used in networks? HUB: Hub is networking component that can be used to connect the networks and it could also be used to extend the size of networks. In a simple way

Assignment , hi i wanted to know if your tutors provide solutions for progr...

hi i wanted to know if your tutors provide solutions for programming assignments

Roster entries in chat application, The roster lets you keep track of the a...

The roster lets you keep track of the availability ("presence") of other users. A roster also allows you to organize users into groups such as "Friends" and "Co-workers". Other IM

Java developer with spring framework prerequisite, Java developer with spri...

Java developer with spring framework prerequisite from anywhere Let me know that you have proven experience in java with spring frame work. Send some sample data and provide inf

Explain identifiers in java, Explain Identifiers in Java ? Identifiers ...

Explain Identifiers in Java ? Identifiers are the names of variables, classes, methods, packages and interfaces. Unlike literals they are not the things themselves, only ways o

Program for randomly generated 3- digit number matches, Program for Randoml...

Program for Randomly Generated 3- Digit Number Matches This assignment demonstrates your ability to use basic Java syntax including selection and looping statements. You will

#, Consider the following code? What input is needed for x in order for the...

Consider the following code? What input is needed for x in order for the sum variable that is output at the end of the code to be 12 ? (In other words: what do I need to make X be

List down the names of two array techniques available java, List down the n...

List down the names of two array techniques available in JavaScript. The two techniques thata rae available in java script is: 1. sort( ) [sorts elements within alphabetical

Write a program that will analyze stocks, Write a program in java that will...

Write a program in java that will analyze stock data and purchase stock with the user''s specific risk and investment. User will select risk from a GUI, high, medium or low and inp

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