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

  1. Q1Multiple choice1 mark
    What will be the result of the following Java expression? `int result = 20 - 4 × 2 / 4 + 6 % 3;`
    1. (a)16
    2. (b)14
    3. (c)20
    4. (d)18
    Show answer and step marks
    1. Correct option: (d) 18. Evaluating multiplication, division and modulus first from left to right: 4∗2=84 * 2 = 8, 8/4=28 / 4 = 2, and 6%3=06 \% 3 = 0, followed by subtraction and addition: 20−2+0=1820 - 2 + 0 = 18.+1
    Answer: (d)
  2. Q2Multiple choice1 mark
    After the statements int a = 12; and a *= a - 4; what is the value of a?
    1. (a)8
    2. (b)48
    3. (c)84
    4. (d)96
    Show answer and step marks
    1. Correct option: (d) 96+1
    Answer: (d)
  3. Q3Multiple choice1 mark
    Which operator in Java acts as a shorthand ternary operator taking three operands?
    1. (a)Assignment operator (=)
    2. (b)Conditional operator (? :)
    3. (c)Logical operator (&&)
    4. (d)Relational operator (>)
    Show answer and step marks
    1. Correct option: (b) Conditional operator (? :). The conditional operator `? :` is Java's ternary operator used as a shorthand for if-else constructs.+1
    Answer: (b)
  4. Q4Short answer2 marks
    While 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
    1. The && operator has higher precedence than ||, so sugar < 4 && cups > 5 is evaluated first: sugar < 4 is false, so the && expression is false.+1
    2. 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.
  5. Q5Long answer4 marks
    A 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
    1. (a) Unary minus applied to fee gives credit = -4+1
    2. (b) units > 5 is true (6 > 5), so extra = units - 5 = 1+1
    3. (c) total = 6 × 15 + 4 - 1 = 90 + 4 - 1 = 93+1
    4. (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
  6. Q6Long answer4 marks
    Consider 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
    1. After execution of `m += n;`, `m` becomes 12+5=1712 + 5 = 17 and `n` remains 55.+1
    2. After execution of `n -= m × 2;`, `n` becomes 5−(17×2)=5−34=−295 - (17 \times 2) = 5 - 34 = -29. Therefore, values after two statements are `m = 17`, `n = -29`.+1
    3. For the third statement `m *= n + 10;`, substitute values: m=17×(−29+10)=17×(−19)m = 17 \times (-29 + 10) = 17 \times (-19).+1
    4. Perform the multiplication: 17×−19=−32317 \times -19 = -323. 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
See a sample marked answer sheet

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

More Class 9 Computer Applications mock tests