Skip to content
Sharp

Core Java · interview question

Given the following code snippet, what will be the value of 'discount' after execution? boolean isMember = true; int totalAmount = 150; double discount = isMember && totalAmount > 100? 0.10 : 0.05;?

Multiple choiceMediumchapter-1-curatedpremiumcore-javaoperators-and-expressions
java
boolean isMember = true;
int totalAmount = 150;
double discount = isMember && totalAmount > 100 ? 0.10 : 0.05;
Choose one answer
Answer and explanation

Correct answer

D. 0.10

Why

The ternary operator evaluates the condition 'isMember && totalAmount > 100'. Both conditions are true, so 'discount' is set to 0.10.

Test yourself on Core Java

A free test with instant, explained results. No account needed.

Start free test
All Core Java questions →