MCQEasy1 mark
1
Choose the correct answers to the questions from the given options. (Do not copy the questions, write only the correct answers.)
Read the if program segment given below: if(a > b) z = 25; else z = 35; Which one of the following is the correct conversion of the if program segment to ternary?
Topic: The ternary operator
Previous-year question practice database
Try it
Pick an option and check your answer. The full worked answer is below either way.
Answer
Exam answer
(b) z = a > b ? 25 : 35;.
Explanation
The ternary operator has the form: variable = condition ? value_if_true : value_if_false. Two checks settle it. First the punctuation — the question mark comes before the colon, which eliminates (c) and (d). Then the order — the if branch assigns 25 when a > b is true, so 25 must come first, which eliminates (a). Read it aloud as "if a > b then 25 else 35".
In words
z = a > b ? 25 : 35;.
More from Revision Tour II
The earth spins on its axis completing one rotation in a day. The earth revolves around the sun in 365 days to complete one revolution. What is the Java concept depicted in the given picture?2026Rewrite the following program segment using a for loop.
int a = 5, b = 10;
while(b > 0)
{
b -= 2;
}
System.out.println(a * b);2026Users must be above 10 years to open a self-operated bank account. Write this logic using a ternary operator and store the result (the eligibility message) in a String variable named idStatus and print it.2026Give the output of the following program segment and mention how many times the loop is executed.
int K = 1;
do
{
K += 2;
System.out.println(K);
} while(K <= 6);2026Write a program to accept a number and check if it is a Mark number or not. A number is said to be Mark when the sum of the squares of each digit is an even number as well as the last digit of the sum and the last digit of the number given is the same.
Example: n = 246
sum = 2 x 2 + 4 x 4 + 6 x 6 = 56
56 is an even number as well as last digit is 6 for both sum as well as the number.2026Select the infinite loop:2025