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 3 Solutions
Starting Out with Java: From Control Structures through Objects (7th Edition) (What's New in Computer Science)
Additional Engineering Textbook Solutions
Objects First with Java: A Practical Introduction Using BlueJ (6th Edition)
Problem Solving with C++ (10th Edition)
Starting Out with Programming Logic and Design (5th Edition) (What's New in Computer Science)
Absolute Java (6th Edition)
Starting Out with C++: Early Objects (9th Edition)
Problem Solving with C++ (9th Edition)
- 4. Write an if statement that increases pay by 3% if score is greater than 90, otherwise increases pay by 1%.arrow_forwardWrite an if statement that assigns 1 to x if y is greater than 0.arrow_forwardWrite an if statement for the following : use if statement that sets the variable fees to 50 if the flag variable max is set totrue.arrow_forward
- Write 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_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 an if-else statement that asks the user to enter the speed at which he is driving. If the speed is more than 50 print ‘Speed in limit’, else print ‘Speed should be checked’.arrow_forward
- Write an if-else statement that displays "Speed is normal" if the speed variable is 24–56. "Speed is abnormal" if the speed variable is outside this range.arrow_forwardRewrite the following conditional expression with an if-else statement. sum /= x = = 4 ? y : 6 + y;arrow_forwardWrite a multiway if-else statement that classifies the value of an int variable ninto one of the following categories and writes out an appropriate message:n < 0 or 0 ≤ n < 100 or n ≥ 100Hint: Remember that the Boolean expressions are checked in order.arrow_forward
- A software company sells a package that retails for $109. Quantity discounts are given according to the following table.Quantity Discount10 - 39 10%40 - 65 18%66 - 90 27%91 - 120 35%121 – 199 42%200 or more 48%Write a program using the if/else if/else statement that asks for the number of units sold and computes the total cost of the purchase and the savings due to the discount applied. The program should also display the number of units purchased and the discount in percentage. The output should include the following text:Number of units purchased is:Discount applied is:Total savings due to discount is:The total cost of the purchase is:Do NOT use the switch statement, any logical operator or anything that looks like one in the program. You will not receive credit for the program if you do.arrow_forward5. Write an efficient if statement to assign x the value 1 if x ≤ 1.5, 2 if 1.5arrow_forwardWrite an if statement for the following: use if/else statement that assigns 0.10 to commission unless sales is greater than orequal to 50000, in which case it assigns 0.20 to commission.arrow_forward
- EBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENT