Skip to content
Computer ApplicationsICSE Class 8 · Program Coding

Java Operators, Expressions and Scanner Input: ICSE Class 8 with Outputs

Updated 17 October 2026 · Fact-checked

Java has arithmetic (+ - * / %), relational (> < >= <= == !=), logical (&& || !) and assignment (=) operators. Integer division drops the decimal part and % gives the remainder. Multiplication, division and remainder come before addition and subtraction. The Scanner class reads input with nextInt, nextDouble, next and nextLine.

Integer division counts the full groups (17 / 5 = 3), % gives what is left (2), and a decimal operand makes the answer 3.4.

Illustration drawn for QuestionBuddy.

Understand Operators, Expressions and Input with Scanner in Java

Arithmetic. With int a = 17, b = 5: a + b is 22; a - b is 12; a * b is 85; a / b is 3 (int divided by int drops the decimal part); a % b is 2 (remainder); 17.0 / 5 is 3.4 (a decimal operand gives a decimal answer).

Relational (result true or false): a > b true; a == b false; a != b true.

Logical. && is AND (both true), || is OR (at least one true), ! is NOT. With a = 17, b = 5: a > 10 && b > 10 is false; a > 10 || b > 10 is true; !(a > b) is false.

Assignment. = stores the value on the right in the variable on the left. int x = 10; x = x + 5; makes x 15; then x = x * 2; makes it 30. Do not confuse = (assign) with == (compare).

Order. Brackets first; then * / %; then + -. With int y = 7; y % 3 + y / 2 is 1 + 3 = 4.

Joining text. "Sum = " + 3 + 4 prints Sum = 34, but "Sum = " + (3 + 4) prints Sum = 7.

Scanner.

import java.util.Scanner;
class Interest
{
    public static void main(String args[])
    {
        Scanner sc = new Scanner(System.in);
        double p = sc.nextDouble();
        double r = sc.nextDouble();
        double t = sc.nextDouble();
        double si = p * r * t / 100;
        System.out.println("Simple interest = " + si);
    }
}

Input 5000, 8 and 3 gives Simple interest = 1200.0 (5000 x 8 x 3 = 120000; 120000 / 100 = 1200). import makes the class available; nextInt reads an int, nextDouble a double, next one word, nextLine a whole line. A double with a whole value prints with .0.

Operators, Expressions and Input with Scanner in Java: key facts

Operator groups
Arithmeticadd, subtract, multiply, divide, remainder
Relationalgreater, less, equal, not equal
LogicalAND, OR, NOT
Assignment=
Relational and logical give true or false.
Integer division
  • Int divided by int drops the decimal
  • Remainder operator gives what is left
  • 17 / 5 = 3
  • Remainder of 17 by 5 = 2
  • 17.0 / 5 = 3.4
One decimal operand gives a decimal answer.
Scanner methods
nextIntint
nextDoubledouble
nextone word
nextLinewhole line
Import java.util.Scanner first.

How to answer Operators, Expressions and Input with Scanner in Java questions

Use this to evaluate or write expressions.

  1. 1Mark the data type of each operand.
  2. 2Apply brackets, then * / %, then + -.
  3. 3For int division keep only the whole part.
  4. 4For text joining, work left to right and check where the text starts.
  5. 5For Scanner programs, list the inputs in the order they are read.

Operators, Expressions and Input with Scanner in Java 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.

A hypothetical bill splitter

Suppose 5 friends share a bill of 1000 rupees on a trip; a program uses int bill = 1000, n = 5.

Write the share per friend and the leftover when the bill is 1003.

Try it first, then show the solutionSolution
  1. 1000 / 5 = 200.
  2. For 1003, 1003 / 5 = 200 (integer division).
  3. 1003 % 5 = 3 leftover.

Answer: Each friend pays 200 for 1000; for 1003 each pays 200 and 3 rupees are left over.

Memory hook: / shares, % leftovers.

Tricks to remember Operators, Expressions and Input with Scanner in Java

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

  • Slash shares, percent leftovers

    / gives the quotient, % the remainder for ints.

    Use it when: Division of integers.

  • One equals assigns, two compare

    = assigns, == compares.

    Use it when: Common slip.

Operators, Expressions and Input with Scanner in Java: solved examples

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

Example 1: Integer division · 1 mark · MCQBoard level

What is the value of 17 / 5 when both are int?
(a) 3.4 (b) 3 (c) 2 (d) 4

Try it first, then show the solutionSolution
  1. int divided by int drops the decimal part.

Answer: (b) 3.

Example 2: Relational results · 2 marks · Short answerBoard level

With a = 17 and b = 5 give the values of a > b, a == b and a != b. (2 marks)

Try it first, then show the solutionSolution
  1. a > b is true (1).
  2. a == b is false and a != b is true (1).

Answer: true, false, true.

Example 3: Order of evaluation · 3 marks · Short answerHarder board level

Find the value of int y = 7; y % 3 + y / 2 and of 2 + 3 * 4 % 5. (3 marks)

Try it first, then show the solutionSolution
  1. y % 3 = 1 and y / 2 = 3, so 4 (1).
  2. 3 * 4 = 12, 12 % 5 = 2 (1).
  3. 2 + 2 = 4 (1).

Answer: 4 and 4.

Example 4: Text joining · 4 marks · Long answerHarder board level

What do these print? (i) System.out.println("Sum = " + 3 + 4); (ii) System.out.println("Sum = " + (3 + 4)); (iii) System.out.println(3 + 4 + " is the sum"); (4 marks)

Try it first, then show the solutionSolution
  1. (i) Sum = 34 (1).
  2. (ii) Sum = 7 (1).
  3. (iii) 3 + 4 is evaluated first as 7 (1).
  4. So it prints 7 is the sum (1).

Answer: (i) Sum = 34 (ii) Sum = 7 (iii) 7 is the sum.

Example 5: Trace assignments and logic · 4 marks · Long answerHOTS / competency

Write the output:

int x = 8;
x = x + 2;
x = x * 4;
System.out.println(x);
System.out.println(x > 30 && x <= 40);
System.out.println(!(x == 40));

(4 marks)

Try it first, then show the solutionSolution
  1. x becomes 10, then 40 (1).
  2. First print: 40 (1).
  3. 40 > 30 and 40 <= 40 are both true, so true (1).
  4. x == 40 is true, so !(true) is false (1).

Answer: 40
true
false (hand-traced).

Where students lose marks in Operators, Expressions and Input with Scanner in Java

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

  • Mistake: Expecting 3.4 from 17 / 5

    int division drops the decimal part.

    Wrong working

    17 / 5 = 3.4

    Right working

    17 / 5 = 3

    Do this: Use 17.0 / 5 for 3.4.

    Usually costs: 1 mark

  • Mistake: Using = to compare

    Comparison uses ==.

    Wrong working

    if (a = b)

    Right working

    if (a == b)

    Do this: Two equals for comparing.

    Usually costs: 1 mark

  • Mistake: Missing the import

    Scanner needs importing.

    Wrong working

    No import line.

    Right working

    import java.util.Scanner;

    Do this: Write it at the top.

    Usually costs: 1 mark

Exam tips

  • Write the output exactly, including .0 for whole doubles.
  • Show the order of evaluation in a line.
  • Mention the data type when explaining a result.
  • Check joined text from left to right.

Practice questions on Operators, Expressions and Input with Scanner in Java

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

    Which operator gives the remainder?
    (a) / (b) * (c) % (d) &&

    Hint

    The percent sign.

    Answer

    (c) %.

  2. Q2 · 2 marks · Short answerBoard level

    What is the value of 17.0 / 5 and why does it differ from 17 / 5? (2 marks)

    Hint

    A decimal operand.

    Answer

    17.0 / 5 is 3.4 because a decimal operand gives a decimal answer; 17 / 5 is 3 because int division drops the decimal part.

  3. Q3 · 3 marks · Short answerHarder board level

    With a = 17 and b = 5 find: a > 10 && b > 10, a > 10 || b > 10 and !(a > b). (3 marks)

    Hint

    AND needs both.

    Answer

    false, true, false.

  4. Q4 · 4 marks · Long answerHarder board level

    Write a Java program to read principal 5000, rate 8 and time 3 as doubles and print the simple interest and the amount, and give the output. (4 marks)

    Hint

    Use Scanner and nextDouble.

    Answer

    Read p, r and t with nextDouble. si = p * r * t / 100 = 1200.0; amt = p + si = 6200.0. Output: Simple interest = 1200.0 and Amount = 6200.0.

  5. Q5 · 4 marks · Long answerHOTS / competency

    A student writes if (x = 5). Explain the mistake and the correct comparison, and state the type of error. (4 marks)

    Hint

    Assign versus compare.

    Answer

    The single = assigns 5 to x instead of comparing; the comparison is x == 5. Java reports this as a compile error because an if condition must be true or false and an assignment gives a number.

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.What does % give?Show answer

    The remainder.

  2. 2.What does && mean?Show answer

    Logical AND.

  3. 3.Which method reads a double?Show answer

    nextDouble.

  4. 4.What does != mean?Show answer

    Not equal to.

  5. 5.What does 17 / 5 give for ints?Show answer

    3.

  6. 6.Which class reads keyboard input?Show answer

    Scanner.

Operators, Expressions and Input with Scanner in Java: frequently asked questions

Why does a double print 1200.0?

A double with a whole value prints with .0.

Is == the same as =?

No, = assigns and == compares.

Does nextLine read one word?

No, next reads a word; nextLine reads a whole line.