Skip to content
Computer ScienceISC Class 12 · Chapter 7

Variables, Constants and Expressions in Java: ISC Class 12 Computer Science

Updated 15 October 2026 · Fact-checked

A variable is a name for a storage location whose value can change; a final variable is a named constant. Expressions combine variables, constants and operators, and Java evaluates them by precedence and associativity. ISC Class 12 also asks how the left and right sides of an assignment differ.

What Variables, Expressions is about

The syllabus asks for:
1. Variables as names for values; named constants (final).
2. Expressions (arithmetic and logical) and their evaluation: operators, associativity and precedence.
3. The assignment operation and the difference between the left-hand side and right-hand side of an assignment.

This is the grammar of every Java statement. In the paper it appears in output-prediction items in Part I, in fill-in-the-blank code (?1?, ?2?, ?3?) in Question 2, and throughout Section B programs, where wrong precedence or integer division silently corrupts results.

All code on this page was compiled and run, and the outputs shown are exactly as printed.

Weightage: CISCE publishes no chapter or unit weightage for ISC Computer Science. Variables, Expressions is part of Section B, 7 of the 2027 syllabus and can be asked anywhere in the 70-mark Paper 1 (Part I compulsory: ten 1-mark items and a 10-mark short-answer question; Part II: two of three 10-mark questions in each of Sections A and B, and two of three 5-mark questions in Section C).Source: CISCE ISC Computer Science (868) syllabus, examination year 2027; latest Paper 1 specimen (2025) and the 2025 board paper

Key concepts

Variables and named constants

A variable is a named memory location that holds a value of a declared type; the value can change while the program runs.
Declaration: type name; e.g. int count;
Initialisation: int count = 0;

Kinds of variables by where they are declared:
1. Instance variables: inside the class, outside methods; one copy per object.
2. Class (static) variables: declared static; one shared copy.
3. Local variables: inside a method or block; exist only while it runs; must be given a value before use (no default).
4. Parameters: variables in a method header that receive argument values.

Named constant: a variable declared final, whose value cannot change after it is assigned:
final double TAX = 0.05;
static final double PI = 3.14159; (a class constant shared by all objects).
Advantages: meaningful names instead of 'magic numbers', one place to change a value, protection against accidental change. Assigning to a final variable again is a compile-time error.

Naming rules: letters, digits, _ and the currency sign; not starting with a digit; not a keyword; case-sensitive. Convention: camelCase for variables, UPPER_CASE for constants.

Worked example

[2] What is a named constant? Give two advantages of using one. (Understand)

Try it first, then show the solutionSolution
  1. A variable declared with final whose value cannot be changed after initialisation, e.g. final double TAX = 0.05; - 1 mark.
  2. Advantages: readable meaningful name instead of a bare number; the value is changed in one place and is protected from accidental change - 1 mark.

Answer: A named constant is a final variable whose value is fixed once assigned (final double TAX = 0.05;). It makes code readable, lets the value be changed in one place, and the compiler stops accidental reassignment.

Operators and expressions

An expression is a combination of operands (variables, constants, method calls) and operators that evaluates to a single value.

Arithmetic expressions: + - * / % with numeric operands; integer division truncates towards zero (-7 / 2 = -3) and % takes the sign of the dividend (-7 % 2 = -1).
Relational expressions: < <= > >= == != give boolean results.
Logical expressions: && (AND), || (OR), ! (NOT) combine boolean values.

  • Short-circuit evaluation: in a && b, if a is false, b is not evaluated; in a || b, if a is true, b is not evaluated. The non-short-circuit & and | always evaluate both sides.

Conditional (ternary): condition ? value1 : value2.
Unary: + - ++ -- !.
Assignment: = += -= *= /= %=.

Mathematical expressions in Java: use Math methods: Math.sqrt(x), Math.pow(x, y), Math.abs(x), Math.max(a, b), Math.round(x). For example b² - 4ac is written b * b - 4 * a * c, and the quadratic root is (-b + Math.sqrt(b * b - 4 * a * c)) / (2 * a) (the brackets round 2 * a are essential).

Worked example

[2] Write the Java expression for the mathematical expression (a + b)² ÷ 2ab and for the simple interest p × r × t ÷ 100. (Apply)

Try it first, then show the solutionSolution
  1. (a + b) * (a + b) / (2 * a * b) or Math.pow(a + b, 2) / (2 * a * b) - 1 mark.
  2. p * r * t / 100 (use a double for p or 100.0 to avoid integer division) - 1 mark.

Answer: (a + b) * (a + b) / (2 * a * b) and p * r * t / 100.0.

Precedence and associativity

Precedence decides which operator is applied first; associativity decides the order among operators of the same precedence.

Level (high to low)OperatorsAssociativity
1postfix x++ x--left to right
2unary ++x --x + - ! (cast)right to left
3* / %left to right
4+ -left to right
5< <= > >=left to right
6== !=left to right
7& (single ampersand)left to right
8single-bar ORleft to right
9&&left to right
10double-bar OR (logical OR)left to right
11? :right to left
12= += -= *= /= %=right to left

Brackets override precedence. Examples from the program below: 2 + 3 * 4 - 10 / 4 = 2 + 12 - 2 = 12; 20 - 6 - 4 = 10 (left to right); 100 / 10 / 5 = 2; a = b = c = 5 assigns right to left.

// Precedence, associativity, short-circuit evaluation and assignment.
public class Precedence
{
    static int calls = 0;

    static boolean check(boolean v)
    {
        calls++;                          // counts how often this method is evaluated
        return v;
    }

    public static void main(String[] args)
    {
        System.out.println(2 + 3 * 4 - 10 / 4);      // * and / first: 2 + 12 - 2
        System.out.println(20 - 6 - 4);               // left to right: (20 - 6) - 4
        System.out.println(100 / 10 / 5);             // left to right: (100 / 10) / 5
        System.out.println(-7 / 2 + " " + -7 % 2);    // truncation towards zero

        int a, b, c;
        a = b = c = 5;                    // assignment is right to left
        a += b *= 2;                      // b becomes 10, then a = 5 + 10
        System.out.println(a + " " + b + " " + c);

        int x = 4;
        boolean r1 = x > 5 && check(true);   // false && ...: check is NOT called
        boolean r2 = x < 5 || check(true);   // true || ...: check is NOT called
        boolean r3 = x < 5 & check(true);    // non-short-circuit &: check IS called
        System.out.println(r1 + " " + r2 + " " + r3 + " calls=" + calls);

        System.out.println(!(x > 2) || x % 2 == 0 && x != 4);  // ! then &&, then ||

        int m = 7, n = 4;
        int big = m > n ? m : n;          // ternary
        System.out.println(big + " " + (m % n == 0 ? "divisible" : "not divisible"));

        double avg = (m + n) / 2;         // integer division happens first
        double avg2 = (m + n) / 2.0;
        System.out.println(avg + " " + avg2);
    }
}

Output:

12
10
2
-3 -1
15 10 5
false true true calls=1
false
7 not divisible
5.0 5.5

Notes: in a += b *= 2, b *= 2 is done first (b = 10) and then a = 5 + 10 = 15. calls = 1 shows that check( ) ran only for the non-short-circuit &. With x = 4, !(x > 2) is false and x % 2 == 0 && x != 4 is false, so the whole expression is false (&& is applied before ||).

Worked example

[2] Evaluate 2 + 3 * 4 - 10 / 4 and 100 / 10 / 5 in Java, showing the order of operations. (Apply)

Try it first, then show the solutionSolution
  1. 3 * 4 = 12 and 10 / 4 = 2 (integer division) first; then 2 + 12 - 2 = 12 - 1 mark.
  2. Same precedence, left to right: 100 / 10 = 10, then 10 / 5 = 2 - 1 mark.

Answer: 12 and 2.

Assignment: left-hand side versus right-hand side

In an assignment variable = expression;
1. The right-hand side (RHS) is an expression; it is evaluated first to produce a value (an r-value).
2. The left-hand side (LHS) must be a variable, a storage location (an l-value), not a value or expression. 5 = x; or a + b = c; are errors.
3. The value is then stored in the LHS location, replacing the old value.

So in count = count + 1; the count on the RHS means 'the current value' and the count on the LHS means 'the location to store into'. This is why the same name can appear on both sides.

Assignment is itself an expression whose value is the value assigned, which allows chains (a = b = c = 5, evaluated right to left).

Compound assignment a op= b means a = (type of a) (a op b): it evaluates a once and includes an automatic cast.

Swapping two variables needs a temporary: t = a; a = b; b = t;. Writing a = b; b = a; loses the original a.

Worked example

[2] Explain the difference between the two uses of x in x = x * 2 + 1; and give the result if x was 4. (Understand)

Try it first, then show the solutionSolution
  1. RHS x is read as a value (4) to compute 4 * 2 + 1 = 9; LHS x is the storage location - 1 mark.
  2. The result 9 is stored in x, replacing 4 - 1 mark.

Answer: On the right, x supplies its current value (4) to the expression; on the left, x names the location where the result (9) is stored.

Expressions in a complete program: slab tariffs with constants

Programs that compute charges are a common Section B and practical pattern. Use final constants for rates, a clear if-else-if ladder for the slabs, and brackets to make the order of operations explicit.

Tariff used here: first 10 kilolitres at Rs 8, the next 20 at Rs 12, the rest at Rs 20 per kilolitre; a meter charge of Rs 50 is added and then 5 per cent tax on the total.

import java.util.Scanner;

// Computes a water bill from a slab tariff using named constants (final).
// First 10 kilolitres: Rs 8 per kl; next 20 kl: Rs 12 per kl; above 30 kl: Rs 20 per kl.
// A fixed meter charge of Rs 50 is added, then 5 per cent tax on the total.
public class WaterBill
{
    final double RATE1 = 8, RATE2 = 12, RATE3 = 20;
    final double METER = 50, TAX = 0.05;

    String name;
    double units;
    double bill;

    WaterBill()
    {
        name = "";
        units = 0;
        bill = 0;
    }

    void accept()
    {
        Scanner sc = new Scanner(System.in);
        System.out.println("Enter name and kilolitres used:");
        name = sc.next();
        units = sc.nextDouble();
    }

    void compute()
    {
        double charge;
        if (units <= 10)
            charge = units * RATE1;
        else if (units <= 30)
            charge = 10 * RATE1 + (units - 10) * RATE2;
        else
            charge = 10 * RATE1 + 20 * RATE2 + (units - 30) * RATE3;
        bill = (charge + METER) * (1 + TAX);
    }

    void display()
    {
        System.out.println("Name: " + name);
        System.out.println("Units: " + units);
        System.out.println("Amount payable: Rs " + Math.round(bill * 100) / 100.0);
    }

    public static void main(String[] args)
    {
        WaterBill ob = new WaterBill();
        ob.accept();
        ob.compute();
        ob.display();
    }
}

Input: Meera 36

Enter name and kilolitres used:
Name: Meera
Units: 36.0
Amount payable: Rs 514.5

Check: 10 × 8 + 20 × 12 + 6 × 20 = 80 + 240 + 120 = 440; (440 + 50) × 1.05 = 514.5. Other runs: 8 kl → (64 + 50) × 1.05 = 119.7; 25 kl → (80 + 180 + 50) × 1.05 = 325.5.

The expression Math.round(bill * 100) / 100.0 rounds to two decimal places: multiply, round to a whole number, then divide by a double so that the division is not an integer division.

Worked example

[2] Why does the program divide by 100.0 and not 100 in Math.round(bill * 100) / 100.0? (Analyse)

Try it first, then show the solutionSolution
  1. Math.round returns a long; long / 100 would be integer division and drop the decimals - 1 mark.
  2. Dividing by the double 100.0 promotes the result to double, keeping two decimal places (514.5) - 1 mark.

Answer: Because Math.round gives a whole number (long); dividing by the int 100 would truncate the decimals, while dividing by 100.0 makes it a double division that keeps them.

Variables, Expressions in real life

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

Named constants

Imagine a shop whose billing program uses the number 0.18 in fifty places for tax, and the tax rate changes.

How would a named constant help?

Try it first, then show the solutionSolution
  1. Declare final double GST = 0.18; once and use GST everywhere.
  2. When the rate changes, edit one line; the name also explains what the number means.

Answer: With a named constant the rate is changed in one place and the code reads clearly; the compiler also prevents accidental changes.

Memory hook: Name the number once, use it everywhere.

Short-circuit evaluation

Suppose a program checks if (d != 0 && total / d > 5) to avoid dividing by zero when no days have been recorded.

Why does this not crash when d is 0?

Try it first, then show the solutionSolution
  1. && evaluates the left side first; d != 0 is false.
  2. The right side (the division) is skipped, so no ArithmeticException occurs.

Answer: Short-circuit && stops after the false left condition, so the division is never attempted when d is 0.

Memory hook: Guard first, then divide.

Precedence

Imagine a calculator app that computes an average as a + b / 2 and shows 8 for marks 6 and 4.

What went wrong and how is it fixed?

Try it first, then show the solutionSolution
  1. / has higher precedence than +, so it computes 6 + 4 / 2 = 6 + 2 = 8.
  2. Use brackets and a double: (a + b) / 2.0 = 5.0.

Answer: Precedence made the division happen first; brackets fix the order and 2.0 avoids integer division.

Memory hook: When in doubt, bracket it out.

Topics in this chapter

Variables, Expressions: syntax and key facts

Precedence (high to low)
  1. 1.unary
  2. 2.* / %
  3. 3.+ -
  4. 4.relational
  5. 5.== !=
  6. 6.&&
  7. 7.||
  8. 8.?:
  9. 9.assignment
Brackets override.
Associativity
Binary arithmetic: left to right; assignment, unary, ?: : right to left
20 - 6 - 4 = 10; a = b = c = 5.
Short circuit
  1. 1.false && x
  2. 2.false (x skipped); true || x
  3. 3.true (x skipped)
& and | evaluate both.
Compound assignment
a op= b ≡ a = (type) (a op b)
Includes an implicit cast.
Round to 2 places
Math.round(x * 100) / 100.0
Divide by a double.
Constant
final type NAME = value;
Reassignment is a compile error.

How the board asks Variables, Expressions

The question patterns to expect, and the method that works for each.

Question typeHow it is askedMethod
Output predictionEvaluate expressions with mixed operators, increments, integer division, short-circuit logic and ternary operators.Apply precedence, then associativity; track side effects such as ++ and method calls.
Writing Java expressionsConvert a mathematical formula into a Java expression.Use Math methods, explicit * signs and brackets around numerators and denominators.
Fill in the blanksSupply a missing expression or assignment in a method.Decide what the variable represents; test with one value.
Short theoryfinal constants; LHS versus RHS; precedence and associativity definitions.Definition plus a one-line example.

Tricks to remember Variables, Expressions

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

  • 'Please Multiply And Relate Equally, Then Assign'

    Postfix/unary, Multiplicative, Additive, Relational, Equality, logical (&& then ||), ternary, Assignment.

    Use it when: Precedence order.

  • Left is a box, right is a value

    The LHS is a box to put into; the RHS is what goes in.

    Use it when: Assignment.

  • && stops at false, || stops at true

    AND gives up on the first 'no'; OR is happy with the first 'yes'.

    Use it when: Short-circuit evaluation.

Variables, Expressions: board-level solved questions

Ordered from board level to HOTS. Cover the solution, write your own, then compare step by step.

Example 1: Associativity · 1 mark · MCQBoard level

The value of 20 - 6 - 4 in Java is:
(a) 18
(b) 10
(c) 22
(d) 14

Try it first, then show the solutionSolution
  1. Subtraction is left-associative.
  2. (20 - 6) - 4 = 10 (confirmed by the Precedence program).

Answer: (b) 10.

Example 2: Negative division · 1 mark · Very short answerBoard level

What are -7 / 2 and -7 % 2 in Java?

Try it first, then show the solutionSolution
  1. Integer division truncates towards zero: -3.5 → -3.
  2. The remainder takes the sign of the dividend: -7 - (-3 × 2) = -1.

Answer: -3 and -1.

Example 3: Assertion-reason: final · 1 mark · Assertion-reasonHarder board level

Assertion (A): A data member declared static final has one fixed value shared by all objects.
Reason (R): static gives one shared copy and final prevents the value from changing.
(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.

Try it first, then show the solutionSolution
  1. static final members are class constants: A is true.
  2. R gives exactly the two reasons: R explains A.

Answer: (a) Both A and R are true and R is the correct explanation of A.

Example 4: Compound assignment chain · 2 marks · Short answerHarder board level

[2] Give the values of a, b and c after: int a, b, c; a = b = c = 5; a += b *= 2; (Apply)

Try it first, then show the solutionSolution
  1. a = b = c = 5 assigns right to left: all three are 5.
  2. a += (b *= 2): b becomes 10, then a = 5 + 10 = 15; c stays 5 (program output: 15 10 5).

Answer: a = 15, b = 10, c = 5.

Example 5: Short-circuit count · 2 marks · Short answerHOTS / competency

[2] A method check( ) increases a counter each time it is called. With x = 4, the statements x > 5 && check(true), x < 5 || check(true) and x < 5 & check(true) are evaluated. How many times is check( ) called? Explain. (Analyse)

Try it first, then show the solutionSolution
  1. x > 5 is false, so && skips check( ); x < 5 is true, so || skips check( ).
  2. & is not short-circuit, so check( ) runs once: total 1 (program output calls=1).

Answer: Once: the short-circuit operators skip the call, but & evaluates both sides.

Example 6: Water bill class · 10 marks · Long answerHOTS / competency

[10] Design a class WaterBill with constants for three slab rates (Rs 8, 12, 20 per kilolitre for the first 10, next 20 and remaining kilolitres), a meter charge of Rs 50 and 5 per cent tax; data members name, units, bill; a constructor; void accept( ); void compute( ); void display( ) printing the bill rounded to two decimals. Write main( ) and give the bill for 36 kl. (Create)

Try it first, then show the solutionSolution
  1. final double RATE1 = 8, RATE2 = 12, RATE3 = 20, METER = 50, TAX = 0.05; data members String name, double units, bill; constructor initialises them.
  2. accept( ): read name with next( ) and units with nextDouble( ).
  3. compute( ): if units <= 10 charge = units × RATE1; else if units <= 30 charge = 10 × RATE1 + (units - 10) × RATE2; else charge = 10 × RATE1 + 20 × RATE2 + (units - 30) × RATE3.
  4. bill = (charge + METER) × (1 + TAX).
  5. display( ): print name, units and Math.round(bill × 100) / 100.0.
  6. main( ): create the object, call accept( ), compute( ), display( ). For 36 kl: (80 + 240 + 120 + 50) × 1.05 = 514.5.

Answer: See the compiled WaterBill program; for 36 kilolitres the amount payable is Rs 514.5.

Case-study practice (Section D style)

Read the situation, then answer every part. In the board paper this is a 6-mark question split into 2 + 1 + 2 + 1 marks.

Formula to code (case-based)

A student converts the roots of ax² + bx + c = 0 into Java: r1 = (-b + Math.sqrt(b * b - 4 * a * c)) / 2 * a;

  1. (i) · 2 marks

    What error has the student made?

    Answer

    Answer: Missing brackets: / 2 * a divides by 2 and then multiplies by a, because / and * have equal precedence and associate left to right.

    1 for identifying, 1 for the reason.

  2. (ii) · 1 mark

    Write the correct expression.

    Answer

    Answer: (-b + Math.sqrt(b * b - 4 * a * c)) / (2 * a)

    1 mark.

  3. (iii) · 2 marks

    For a = 2, b = -6, c = 4, what do the wrong and correct expressions give?

    Answer

    Answer: Discriminant 36 - 32 = 4, sqrt = 2; numerator 6 + 2 = 8. Wrong: 8 / 2 * 2 = 8. Correct: 8 / 4 = 2.

    1 mark each.

  4. (iv) · 1 mark

    What should the program check before calling Math.sqrt?

    Answer

    Answer: That b * b - 4 * a * c is not negative (otherwise the roots are not real and Math.sqrt returns NaN).

    1 mark.

Where the marks are

How a typical answer is split into step marks. Show every step: a right final answer alone rarely earns full marks.

[2] Evaluate a += b *= 2 after a = b = c = 5. (2 marks)

StepMarks
Right-to-left chain gives 5, 5, 5.1
b = 10 first, then a = 15; c = 5.1

[5] Method fare(km, age) with constants. (5 marks)

StepMarks
final constants declared.1
Fare expression.1
Concession condition with || and ternary or if.2
Return and worked value.1

[10] Class WaterBill. (10 marks)

StepMarks
Constants and data members.1
Constructor and accept( ).1
Slab calculation (three cases).3
Meter charge and tax.1
display( ) with rounding.1
main( ).1
Documentation and meaningful names.2

Where students lose marks in Variables, Expressions

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

  • Mistake: Missing brackets in denominators

    / and * have equal precedence and associate left to right, so x / 2 * a means (x / 2) × a.

    Wrong working

    (-b + Math.sqrt(d)) / 2 * a

    Right working

    (-b + Math.sqrt(d)) / (2 * a)

    Do this: Bracket every denominator that has more than one factor.

    Usually costs: 1 mark and wrong output.

  • Mistake: Misreading the conditional operator

    CISCE examiners' comments, 2024: on a fill-in-the-blank method using min = r > min ? ?3? : r;, candidates were 'Unclear about the ? : operator'.

    Do this: Read condition ? valueIfTrue : valueIfFalse; to keep the smaller value, if r > min the result must be min.

    Usually costs: 1 mark.

  • Mistake: Wrong update expression in a loop header

    CISCE examiners' comments, 2025: for the update ?1? in for (int i = a; i != 0; ?1?), candidates 'Wrote i = a/10 or only i/10 instead of i = i/10'.

    Do this: The update must change the loop variable using its own current value: i = i / 10 (or i /= 10). i / 10 alone is an expression that changes nothing.

    Usually costs: 1 mark.

  • Mistake: Integer division in averages and percentages

    (m + n) / 2 with ints truncates even if stored in a double (the Precedence program prints 5.0 instead of 5.5).

    Do this: Divide by 2.0 or cast one operand to double first.

    Usually costs: 1 mark.

Practice questions on Variables, Expressions

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 · Very short answerBoard level

    Which keyword makes a variable a constant?

    Hint

    Cannot change.

    Answer

    final

  2. Q2 · 1 mark · Very short answerBoard level

    Give the value of 10 + 4 % 3 * 2.

    Hint

    % and * first, left to right.

    Answer

    12 (4 % 3 = 1, 1 * 2 = 2, 10 + 2).

  3. Q3 · 1 mark · Very short answerBoard level

    Do local variables get default values?

    Hint

    Compiler checks.

    Answer

    No. A local variable must be assigned before use, otherwise the program does not compile.

  4. Q4 · 1 mark · Very short answerHarder board level

    Give the output of int p = 5; System.out.println(p++ * 2 + --p);

    Hint

    p++ gives 5 then p = 6; --p gives 5.

    Answer

    15 (5 * 2 + 5).

  5. Q5 · 2 marks · Short answerHarder board level

    [2] Write a Java expression for the area of a triangle using Heron's formula √(s(s - a)(s - b)(s - c)) where s = (a + b + c) / 2.

    Hint

    Use 2.0.

    Answer

    double s = (a + b + c) / 2.0; double area = Math.sqrt(s * (s - a) * (s - b) * (s - c)); For sides 3, 4, 5 the area is 6.0.

  6. Q6 · 2 marks · Short answerHarder board level

    [2] What is printed by int x = 3; boolean ok = (x > 2) || (++x > 10); System.out.println(ok + " " + x);?

    Hint

    Is ++x evaluated?

    Answer

    true 3: the left side is true, so || skips ++x and x stays 3.

  7. Q7 · 5 marks · Long answerHOTS / competency

    [5] Write a method double fare(double km, int age) using final constants: Rs 10 base fare plus Rs 6 per km; children under 12 and adults over 60 pay half. Give the fare for 15 km at age 65.

    Hint

    Ternary for concession.

    Answer

    final double BASE = 10, PER_KM = 6; double f = BASE + PER_KM * km; return (age < 12 || age > 60) ? f / 2 : f; For 15 km at 65: (10 + 90) / 2 = 50.0.

  8. Q8 · 10 marks · Long answerHOTS / competency

    [10] Design a class Quadratic with data members a, b, c; a constructor; void accept( ); double disc( ) returning b² - 4ac; and void roots( ) that uses disc( ) to print 'real and distinct' with both roots, 'real and equal' with the root, or 'not real'. Write main( ).

    Hint

    Bracket the denominator.

    Answer

    Constructor sets a = b = c = 0; accept( ) reads them; disc( ) returns b * b - 4 * a * c; roots( ): d = disc( ); if d > 0 print (-b + Math.sqrt(d)) / (2 * a) and (-b - Math.sqrt(d)) / (2 * a); if d == 0 print -b / (2 * a); else print 'not real'. Tests: (1, -5, 6) → 3.0 and 2.0; (1, 2, 1) → -1.0; (1, 1, 1) → not real (checked by running the code).

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.Associativity of =?Show answer

    Right to left.

  2. 2.Which is evaluated first, && or ||?Show answer

    && (higher precedence).

  3. 3.Value of 100 / 10 / 5?Show answer

    2.

  4. 4.What must the LHS of an assignment be?Show answer

    A variable (storage location).

  5. 5.Rounding x to two decimals?Show answer

    Math.round(x * 100) / 100.0.

Best order to study it

  1. Variables, kinds and naming; final constants.
  2. Operators and expressions; Math methods.
  3. Precedence and associativity with practice outputs.
  4. Assignment, LHS and RHS, compound assignment.
  5. Programs that evaluate formulas and slabs.

Quick revision checklist

The night before the exam: can you do each of these without looking?

  • Variable = named storage; local variables need initialising.
  • final makes a constant; static final = class constant.
  • Precedence: unary > * / % > + - > relational > equality > && > || > ?: > =.
  • Left-to-right for arithmetic; right-to-left for = and ?:.
  • && and || short-circuit; & and | do not.
  • LHS is a location, RHS a value; compound assignment casts.
  • Bracket denominators; divide by 2.0 for real averages.

Variables, Expressions: frequently asked questions

Is ++ allowed inside larger expressions in answers?

It is legal, and output questions use it deliberately. In your own programs, keep ++ in separate statements for clarity.

What is the difference between = and ==?

= assigns a value; == compares two values and gives true or false. Writing if (x = 5) is a compile-time error for an int x.

Do I need to memorise the whole precedence table?

Know the main order (unary, multiplicative, additive, relational, equality, &&, ||, ternary, assignment) and use brackets in your own code to avoid ambiguity.

Based on: CISCE ISC 2027 Computer Science (868) syllabus; CISCE ISC Computer Science (868) Paper 1 specimen question paper and answer key (latest specimen, 2025); CISCE Analysis of Pupil Performance, ISC Computer Science (868), 2025; CISCE Analysis of Pupil Performance, ISC Computer Science (868), 2024