Skip to content
Computer ApplicationsICSE Class 9 · Operators in Java

Arithmetic, Relational and Logical Operators in Java with Short-Circuit Evaluation (ICSE Class 9)

Updated 18 October 2026 · Fact-checked

An operator acts on operands. By operand count it is unary (one), binary (two) or ternary (three, only ?:). Arithmetic operators (+ - * / %) compute numbers; with two int operands, / drops the fraction and % gives the remainder, which takes the sign of the left operand. Relational operators (< > <= >= == !=) give true or false. Logical operators (&& || !) join conditions, and && and || stop early (short-circuit) once the result is known.

Notice the downward arrows: once A decides the answer (false for &&, true for ||), B is never checked.

Illustration drawn for QuestionBuddy.

Understand Arithmetic, Relational and Logical Operators with Short-Circuit Evaluation

Forms of operators. The number of operands decides the form: a unary operator takes one (unary minus, !, ++), a binary operator takes two (+ - * / % < == && =) and the ternary operator ?: takes three.

Arithmetic operators. + - * / and % (modulus, the remainder).

  • If both operands are int, / gives an int and the fraction is dropped: 17 / 5 = 3, and -17 / 5 = -3. If either operand is a decimal, the result is decimal: 17 / 5.0 = 3.4.
  • % gives the remainder and takes the sign of the left operand: 23 % 7 = 2, -23 % 7 = -2, 23 % -7 = 2. It also works on decimals: 7.5 % 2 = 1.5.
  • Useful tricks: n % 2 == 0 tests an even number; n % 10 is the last digit; n / 10 removes the last digit; n % k == 0 tests divisibility by k.
  • Precedence: * / % are done before + -, and equal operators go left to right.

Relational operators. < > <= >= == != compare two values and always give a boolean (true or false). Remember = stores a value but == compares.

Logical operators. && (AND) is true only if both sides are true; || (OR) is true if at least one side is true; ! (NOT) reverses the value. Precedence: ! first, then relational, then &&, then ||.

Short-circuit evaluation. In A && B, if A is false the answer is already false, so B is not evaluated. In A || B, if A is true the answer is already true, so B is not evaluated. This matters when B has a side effect (like ++q) or could fail (like a division by zero): in (a != 0) && (b / a > 2) the division never runs when a is 0.

Joining conditions. A range test needs two comparisons joined by &&: n >= 100 && n <= 999. Writing 100 <= n <= 999 is a syntax error in Java.

Neighbouring topics: prefix, postfix, shorthand operators and precedence are on the next page of this chapter.

Arithmetic, Relational and Logical Operators with Short-Circuit Evaluation: key facts

Integer division and remainder
  • int / int gives int (fraction dropped)
  • a % b has the sign of a
  • 23 % 7 = 2, -23 % 7 = -2
Make one operand decimal for a decimal answer.
Logical operators
  • && true only if both true
  • || true if at least one true
  • ! reverses
  • && before ||
Brackets override.
Short-circuit
A && B: B skipped if A is false | A || B: B skipped if A is true
Side effects in B may not happen.
Range test
low <= n && n <= high | never low <= n <= high
Two comparisons joined by &&.

How to answer Arithmetic, Relational and Logical Operators with Short-Circuit Evaluation questions

Use this routine for expression and output questions.

  1. 1Write the value of every variable first.
  2. 2Bracket the expression by precedence: ! then * / % then + - then relational then && then ||.
  3. 3Evaluate each bracket; for int with int, apply integer division; for string joining, work left to right.
  4. 4In && and ||, stop as soon as the answer is fixed and mark the skipped part as not evaluated.
  5. 5Write the final output exactly, with the spaces from the string literals.

Arithmetic, Relational and Logical Operators with Short-Circuit Evaluation in real life

The idea, met in an everyday situation. Answer the question in your own words, then compare with the model answer. The one-line hook is what to remember.

Modulus for splitting units

Suppose a canteen packs samosas in boxes of 6 and 29 samosas are ready.

How many full boxes and how many loose samosas are there?

Try it first, then show the solutionSolution
  1. Full boxes: 29 / 6 = 4 (integer division).
  2. Loose samosas: 29 % 6 = 5.
  3. Check: 4 x 6 + 5 = 29.

Answer: 4 full boxes and 5 loose samosas.

Memory hook: Divide for whole boxes, mod for the leftovers.

Short-circuit AND

Suppose a gate allows entry only if a visitor has a pass and the pass has not expired; a person without a pass is turned away at once.

Why does the guard not check the expiry date for such a person?

Try it first, then show the solutionSolution
  1. Entry needs both conditions true.
  2. The first condition (has a pass) is false.
  3. The result is false whatever the second condition is, so it is skipped.

Answer: The result is already false, so the second check is skipped, exactly like && in Java.

Memory hook: AND stops at the first false.

Tricks to remember Arithmetic, Relational and Logical Operators with Short-Circuit Evaluation

Short memory aids. Say each one aloud once, then use it on a question the same day.

  • Mod takes the left sign

    The sign of a % b follows a, never b.

    Use it when: Negative remainders.

  • AND is strict, OR is lenient

    && needs everything true; || needs just one true.

    Use it when: Logical operators.

  • Stops at the answer

    && stops at the first false; || stops at the first true.

    Use it when: Short-circuit questions.

Arithmetic, Relational and Logical Operators with Short-Circuit Evaluation: solved examples

Ordered from board level to HOTS. Try each one before you open the solution.

Example 1: Remainder · 1 mark · MCQBoard level

What is the value of 29 % 6?
(a) 4 (b) 5 (c) 3 (d) 0

Try it first, then show the solutionSolution
  1. 29 = 4 x 6 + 5, so the remainder is 5.

Answer: (b) 5

Example 2: Mixed integer and decimal division · 3 marks · Short answerHarder board level

Give the output:

int a = 17, b = 5;
System.out.println(a / b + " " + a % b + " " + (double) a / b + " " + (a / b) * b + a % b);
Try it first, then show the solutionSolution
  1. a / b = 3 and a % b = 2; (double) a / b = 17.0 / 5 = 3.4. (1 mark)
  2. (a / b) * b = 15 and a % b = 2 are both computed before the + signs. (1 mark)
  3. After the string " " the two numbers are joined as text: " " + 15 gives " 15" and then + 2 gives " 152". (1 mark)

Answer: 3 2 3.4 152

Example 3: Logical expressions and an avoided error · 3 marks · Short answerHarder board level

Find the output:

int x = 12, y = 7;
boolean r1 = x > y && x % 2 == 0;
boolean r2 = !(x < y) || y / 0 == 1;
boolean r3 = x % y > 5;
System.out.println(r1 + " " + r2 + " " + r3);
Try it first, then show the solutionSolution
  1. r1: 12 > 7 is true and 12 % 2 == 0 is true, so true. (1 mark)
  2. r2: x < y is false, so !(false) is true; || stops here, so y / 0 is never evaluated and no exception occurs. (1 mark)
  3. r3: 12 % 7 = 5 and 5 > 5 is false. (1 mark)

Answer: true true false

Example 4: Case study: scholarship rule · 4 marks · Case-basedHOTS / competency

A school checks a scholarship with:

int age = 15, marks = 58;
boolean ok = (age >= 14 && age <= 16) && (marks >= 60 || age == 15);
System.out.println(ok);

(i) State the output. (1)
(ii) What is the output if age = 17 and marks = 58? Which part is skipped? (2)
(iii) Why is the range written as two comparisons? (1)

Try it first, then show the solutionSolution
  1. (i) age >= 14 and age <= 16 are both true; marks >= 60 is false but age == 15 is true, so the right bracket is true: true.
  2. (ii) age >= 14 is true but age <= 16 is false, so the first bracket is false and the outer && skips the second bracket: false.
  3. (iii) A single chained comparison is not allowed in Java; each comparison gives a boolean and the two are joined with &&.

Answer: (i) true (ii) false, the second bracket is skipped (iii) Java has no chained comparison.

Example 5: Side effects and short-circuit · 3 marks · Short answerHarder board level

Find the output:

int p = 4, q = 9;
boolean t = (p > 5) && (++q > 9);
boolean u = (p < 5) || (++q > 9);
boolean v = (p > 5) || (++q > 9);
System.out.println(t + " " + u + " " + v + " " + q);
Try it first, then show the solutionSolution
  1. t: p > 5 is false, so ++q is skipped: t = false and q stays 9. (1 mark)
  2. u: p < 5 is true, so ++q is skipped: u = true and q stays 9. (1 mark)
  3. v: p > 5 is false, so ++q runs: q = 10 and 10 > 9 is true, v = true. Output joins t, u, v and q. (1 mark)

Answer: false true true 10

Where students lose marks in Arithmetic, Relational and Logical Operators with Short-Circuit Evaluation

The slips examiners see most often, and what to write instead.

  • Mistake: Giving a decimal for int division

    Both operands are int.

    Wrong working

    17 / 5 = 3.4

    Right working

    17 / 5 = 3 and 17 / 5.0 = 3.4

    Do this: Look at the types before dividing.

    Usually costs: 1 mark

  • Mistake: Wrong sign of the remainder

    The sign of the divisor is used by mistake.

    Wrong working

    -23 % 7 = 5

    Right working

    -23 % 7 = -2

    Do this: The sign follows the left operand.

    Usually costs: 1 mark

  • Mistake: Chaining comparisons

    Mathematics notation is copied.

    Wrong working

    100 <= n <= 999

    Right working

    n >= 100 && n <= 999

    Do this: Join two comparisons with &&.

    Usually costs: 1 to 2 marks

Exam tips

  • In output questions, write every variable after each statement.
  • State clearly which operand of && or || was not evaluated.
  • Remember that + joins text once a String has appeared.
  • Use brackets in long conditions so the examiner sees your intended order.

Practice questions on Arithmetic, Relational and Logical Operators with Short-Circuit Evaluation

Write each answer on paper first. Open the hint only if you are stuck, and the answer only when you have finished.

  1. Q1 · 1 mark · MCQBoard level

    The value of 7 + 8 / 2 * 3 is:
    (a) 19 (b) 21 (c) 10 (d) 12

    Hint

    / and * are done left to right before +.

    Answer

    (a) 19 (8 / 2 = 4, 4 * 3 = 12, 7 + 12 = 19)

  2. Q2 · 2 marks · Very short answerBoard level

    Evaluate: (i) 23 % 7 (ii) -23 % 7 (iii) 23 % -7

    Hint

    The sign follows the left operand.

    Answer

    (i) 2 (ii) -2 (iii) 2

  3. Q3 · 2 marks · Short answerHarder board level

    Find the output:

    int m = 5;
    System.out.println(m / 2 + m % 2 * 3 + 1.5);
    Hint

    Do / and % * first, left to right.

    Answer

    6.5 (m / 2 = 2; m % 2 * 3 = 1 * 3 = 3; 2 + 3 = 5; 5 + 1.5 = 6.5)

  4. Q4 · 3 marks · Short answerHarder board level

    Write Java conditions for: (i) n is a three-digit number; (ii) x is divisible by both 4 and 6; (iii) ch is a lower-case letter.

    Hint

    Join two comparisons with &&.

    Answer

    (i) n >= 100 && n <= 999 (ii) x % 4 == 0 && x % 6 == 0 (iii) ch >= 'a' && ch <= 'z'

  5. Q5 · 1 mark · Assertion-reasonHOTS / competency

    Assertion (A): In (a != 0) && (b / a > 2), a division by zero error does not occur when a is 0.
    Reason (R): The && operator does not evaluate its right operand when the left operand is false.
    (a) Both A and R are true and R is the correct explanation of A. (b) Both A and R are true but R is not the correct explanation of A. (c) A is true but R is false. (d) A is false but R is true.

    Hint

    What does a != 0 give when a is 0?

    Answer

    (a) a != 0 is false, so b / a is never evaluated and R explains A.

Test your recall

Answer in your head or on paper first, then open the card. Pulling an answer out of memory makes it stick far better than re-reading.

  1. 1.How many operands has a binary operator?Show answer

    Two.

  2. 2.What is 29 / 6 for ints?Show answer

    4

  3. 3.What does 29 % 6 give?Show answer

    5

  4. 4.Which operator is the only ternary one?Show answer

    ?:

  5. 5.When is B skipped in A || B?Show answer

    When A is true.

  6. 6.What type of value do relational operators give?Show answer

    boolean

Arithmetic, Relational and Logical Operators with Short-Circuit Evaluation: frequently asked questions

Is % allowed on decimals in Java?

Yes. 7.5 % 2 gives 1.5.

Why use && instead of two separate if statements?

One && joins two conditions in a single expression and skips the second when the first is false.

Are bitwise operators in the syllabus?

No. Use && and || for conditions.