Computer Applications
Give the output of the following:
int f = 10, m = 9;
String e = (m % f == 9)? "YES": "NO";
System.out.print(e);
Answer
Output
YES
Explanation
1. Initial values: f = 10, m = 9
2. Step-by-step evaluation:
m % f: The remainder when 9 is divided by 10 is 9 (9 % 10 == 9).- The condition
m % f == 9is true.
3. Ternary operation: Since the condition is true, "YES" is assigned to e.
4. Output: The value of e is "YES", which is printed.
Related Questions
Evaluate the following if the value of x = 7, y = 5:
x += x++ + x + ++y
Give the output of the following:
int x = 2, y = 4, z = 1; int result = (++z) + y + (++x) + (z++);Rewrite the following program segment using logical operators:
if(x > 5) if(x > y) System.out.println(x + y);Rewrite the following program segment using if-else statements instead of the ternary operator:
String grade = (marks>=90)?"A": (marks>=80)? "B": "C";