ICSE · Class 9 · Computer Applications
Class 9 Operators in Java Mock Test (ICSE)
6 practice questions from Operators in Java, in the style of your board paper, each with a worked answer and the marks for every step. Then take a full chapter test on paper, snap the pages and get every step marked.
Topics in Operators in Java
- Arithmetic, relational and logical operators
- Unary, binary and ternary operators
- Increment and decrement
- Assignment and shorthand operators
- Precedence and associativity
- Writing expressions in Java
Operators in Java practice questions with answers
- Q1Multiple choice1 markWhat will be the result of the following Java expression? `int result = 20 - 4 × 2 / 4 + 6 % 3;`
- (a)16
- (b)14
- (c)20
- (d)18
Show answer and step marks
- Correct option: (d) 18. Evaluating multiplication, division and modulus first from left to right: , , and , followed by subtraction and addition: .+1
Answer: (d) - Q2Multiple choice1 markAfter the statements int a = 12; and a *= a - 4; what is the value of a?
- (a)8
- (b)48
- (c)84
- (d)96
Show answer and step marks
- Correct option: (d) 96+1
Answer: (d) - Q3Multiple choice1 markWhich operator in Java acts as a shorthand ternary operator taking three operands?
- (a)Assignment operator (=)
- (b)Conditional operator (? :)
- (c)Logical operator (&&)
- (d)Relational operator (>)
Show answer and step marks
- Correct option: (b) Conditional operator (? :). The conditional operator `? :` is Java's ternary operator used as a shorthand for if-else constructs.+1
Answer: (b) - Q4Short answer2 marksWhile planning a snack at home, a student writes the following Java code: int cups = 3; int sugar = 5; boolean ready = cups ≥ 2 || sugar < 4 && cups > 5; Find the value stored in ready and give a reason based on the order in which the operators are evaluated.
Show answer and step marks
- The && operator has higher precedence than ||, so sugar < 4 && cups > 5 is evaluated first: sugar < 4 is false, so the && expression is false.+1
- cups ≥ 2 is true, so true || false gives true; hence ready stores true.+1
Answer: ready stores true, because && is evaluated before || and cups ≥ 2 is true. - Q5Long answer4 marksA Java program calculates the bill for an order. The statements below are executed in the given order: int units = 6; int rate = 15; int fee = 4; int extra = (units > 5) ? units - 5 : 0; int credit = -fee; int total = units × rate + fee - extra; (a) Find the value stored in credit after the statement int credit = -fee; is executed. [1] (b) Find the value stored in extra after the statement int extra = (units > 5) ? units - 5 : 0; is executed. [1] (c) Find the value stored in total after the statement int total = units × rate + fee - extra; is executed. [1] (d) State the number of operands taken by the ternary operator ?: in the statement that sets extra. [1]
Show answer and step marks
- (a) Unary minus applied to fee gives credit = -4+1
- (b) units > 5 is true (6 > 5), so extra = units - 5 = 1+1
- (c) total = 6 × 15 + 4 - 1 = 90 + 4 - 1 = 93+1
- (d) ?: takes three operands: the condition, the value if true and the value if false+1
Answer: (a) -4 (b) 1 (c) 93 (d) 3 - Q6Long answer4 marksConsider the following code snippet: `int m = 12, n = 5;` `m += n;` `n -= m × 2;` `m *= n + 10;` (a) What are the values of `m` and `n` after the execution of the first two compound-assignment statements (`m += n;` and `n -= m × 2;`)? [2] (b) Calculate the final value of `m` after the complete code snippet is executed. Show the step-by-step working. [2]
Show answer and step marks
- After execution of `m += n;`, `m` becomes and `n` remains .+1
- After execution of `n -= m × 2;`, `n` becomes . Therefore, values after two statements are `m = 17`, `n = -29`.+1
- For the third statement `m *= n + 10;`, substitute values: .+1
- Perform the multiplication: . Final value of `m` is `-323`.+1
Answer: (a) m = 17, n = -29 (b) m = -323
Take a full Operators in Java test
PrepitUp writes a fresh paper on this chapter at the length you pick. Write it on paper with a timer, photograph the pages, and see the marks for every step and what to practise next.
- 15 min10 marks
- 30 min20 marks
- 1.5 hr40 marks
- 3 hr80 marks
Get your Operators in Java answers marked
Sign in, pick this chapter and a length, write the test on paper and get every step marked.
Sign in to take this test