Concept explainers
Match the conditional expression with the if-else statement that performs the same operation.
a. q = x < y ? a + b : x * 2;
b. q = x < y ? x * 2 : a + b;
c. q = x < y ? 0 : 1;
____ if (x < y)
q = 0;
else
q = 1;
____ if (x < y)
q = a + b;
else
q = x * 2;
____ if (x < y)
q = x * 2;
else
q = a + b;
Want to see the full answer?
Check out a sample textbook solutionChapter 4 Solutions
Starting Out with Java: Early Objects (6th Edition)
Additional Engineering Textbook Solutions
Programming in C
Starting Out with C++: Early Objects (9th Edition)
Objects First with Java: A Practical Introduction Using BlueJ (6th Edition)
Starting Out with Java: From Control Structures through Objects (7th Edition) (What's New in Computer Science)
Starting Out with Java: From Control Structures through Data Structures (3rd Edition)
Modern Database Management (12th Edition)
- 4. Write an if statement that increases pay by 3% if score is greater than 90, otherwise increases pay by 1%.arrow_forwardVariables father and child contains ages of a father and his child.Which if statement checks if father's age is more than 4 times his child's age? Lütfen birini seçin: a. if father // 4 > child: b. if father > 4 * child: c. if father > 4 * child d. if f > 4 * c: e. if father >= 4 * child:arrow_forwardWrite aprogram using nestedif statements that perform the following test: If the variable employed is equal to 'Y' and if worklength is equal or greater than 5, then display the message "Your credit card application is accepted". However, if worklength is less than 5, then display the message "Please provide a guarantor". Otherwise, if the variable employed is equal to 'N', then display the message "Your credit card application is rejected". C.arrow_forward
- Write an if statement that assigns 20 to the variable y, and assigns 40 to the variable z if the variable x is greater than 100. Write an if statement that assigns 0 to the variable b, and assigns 1 to the variable c if the variable a is less than 10. Write an if-else statement that assigns 0 to the variable b if the variable a is less than 10. Otherwise, it should assign 99 to the variable b. Write nested decision structures that perform the following: If amount1 is greater than 10 and amount2 is less than 100, display the greater of amount1 and amount2.arrow_forward5. Write an efficient if statement to assign x the value 1 if x ≤ 1.5, 2 if 1.5arrow_forwardIn C language The if...else statement executes two different codes depending .upon whether the test expression is true or false False True * In C language is invalid identifier su_b O intarrow_forward
- Unlim Write an if-else statement that assigns True to fever if temperature is greater than 98.6; otherwise it assigns False to fever. 1 Enter your codearrow_forwardWrite a if-elif-else statement that distinguishes between a negative number or 0, a number between 0 and 50, and a number greater than or equal 50 by printing one of these three statements: {"It's negative or zero", "It's between 0 and 50", "It's greater than or equal to 50"}.arrow_forwardConvert the if-else statement to a single assignment statement using a conditional expression. Use parentheses around the condition. Enter "Not possible" if appropriate. if (x < 20) { y = X; else { y = 20;arrow_forward
- EBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENT