Skip to content
Computer ApplicationsICSE Class 9 · Chapter 6

Data Processing in Java ICSE Class 9: Input with Scanner, Errors and Comments

Updated 15 October 2026 · Fact-checked

A Java program can get data in three ways: by initialisation (values written in the program before execution), as parameters (values supplied when a method is run) and through an input stream (values typed during execution, read with Scanner methods). ICSE Class 9 also tests packages, the three types of errors (syntax, runtime, logical) and single-line and multi-line comments.

What Data Processing in Java is about

A program that always uses the same numbers is of little use. Real programs take data from the user, process it and report results, and they must cope with mistakes, both the programmer's and the user's. This chapter covers how data gets into a program and what can go wrong.

The CISCE syllabus asks for: initialisation (data before execution); parameters (data at the time of execution); an introduction to packages; input streams (data entry during execution) using the Scanner class methods nextShort(), nextInt(), nextLong(), nextFloat(), nextDouble(), next(), nextLine() and next().charAt(0); the types of errors (syntax, runtime and logical); and single-line (//) and multi-line (/* ... */) comments.

In programs, choose the Scanner method that matches each variable's data type, and remember the classic trap: nextLine() after nextInt() reads an empty line.

Weightage: CISCE publishes no chapter weightage and no question-paper layout for ICSE Class 9 Computer Applications. Class IX is examined by your school: one 100-mark theory paper of 2 hours, plus 100 marks of internal assessment (at least 15 programming assignments and a written project on ethical computing). This is topic 6 of the 2028 syllabus.Source: CISCE ICSE 2028 Computer Applications syllabus, Class IX

Key concepts

Three ways to supply data: initialisation, parameters, input

1. Initialisation (data before execution): values are written into the program itself when variables are declared. They are the same every time the program runs unless the code is changed.
int a = 10, b = 20;

2. Parameters (data at the time of execution): values are passed to a method when it is called. In BlueJ, if main() or any method has parameters, for example void rectangle(int l, int b), BlueJ opens a dialog box asking for the values when you run it. In code, the values are passed as arguments: obj.rectangle(6, 4); prints Area = 24 (as run in this study guide).

3. Input stream (data entry during execution): the program pauses while running and the user types values, which are read with an object of the Scanner class. The values can be different on every run.
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();

Comparison: initialisation is fixed in the code; parameters are given when the method starts; input is given while the program is running, in response to prompts.

Worked example

(2 marks) Distinguish between initialisation and input through the Scanner class.

Try it first, then show the solutionSolution
  1. Initialisation: values assigned in the program before execution; fixed unless the code is edited - 1 mark.
  2. Scanner input: values typed by the user during execution; can change each run - 1 mark.

Answer: In initialisation the values are written into the program (int a = 10;) before it runs, so they stay the same every time. With Scanner input the user types the values while the program runs (a = sc.nextInt();), so the same program can work on different data.

Packages

A package is a group of related classes (and interfaces) stored together, like a folder of files. Packages organise Java's large library and avoid name clashes.

Important built-in packages:

  • java.lang: the basic classes of the language, such as System, String and Math. It is imported automatically (default), so no import statement is needed.
  • java.util: utility classes, including Scanner.
  • java.io: classes for input and output with files and streams.
  • java.awt and javax.swing: classes for graphical user interfaces.
  • java.net: classes for networking.

Using a package: import java.util.*; (all classes) or import java.util.Scanner; (one class). Without an import, the full name java.util.Scanner can be written each time.

The programmer can also create packages, but that is not required in Class IX.

Worked example

(2 marks) What is a package? Why do we not need to import java.lang?

Try it first, then show the solutionSolution
  1. Package: a collection of related classes grouped together, e.g. java.util - 1 mark.
  2. java.lang contains the basic classes (System, String, Math) and is imported by default - 1 mark.

Answer: A package is a group of related classes stored together, such as java.util, which contains Scanner. java.lang holds the fundamental classes like System, String and Math, so Java imports it automatically into every program.

Scanner methods for different data types

After Scanner sc = new Scanner(System.in);

  • sc.nextShort(): reads a short.
  • sc.nextInt(): reads an int.
  • sc.nextLong(): reads a long.
  • sc.nextFloat(): reads a float.
  • sc.nextDouble(): reads a double.
  • sc.next(): reads the next word (token) as a String, stopping at a space or new line.
  • sc.nextLine(): reads the rest of the current line, including spaces, as a String.
  • sc.next().charAt(0): reads the next word and takes its first character, giving a char (Scanner has no nextChar()).

Input items (tokens) may be separated by spaces or new lines. As run in this study guide, with the input
120 45000 9876543210 2.5 3.14159 Good morning
New Delhi India
Yes
the statements
short s = sc.nextShort(); int i = sc.nextInt(); long l = sc.nextLong();
float f = sc.nextFloat(); double d = sc.nextDouble();
String w = sc.next(); String rest = sc.nextLine(); String line = sc.nextLine();
char c = sc.next().charAt(0);
give s = 120, i = 45000, l = 9876543210, f = 2.5, d = 3.14159, w = "Good", rest = " morning" (with the leading space), line = "New Delhi India", c = 'Y'.

Worked example

(2 marks) Write statements to accept (i) a city name that may contain spaces, (ii) a grade letter.

Try it first, then show the solutionSolution
  1. (i) String city = sc.nextLine(); - 1 mark.
  2. (ii) char grade = sc.next().charAt(0); - 1 mark.

Answer: (i) String city = sc.nextLine();
(ii) char grade = sc.next().charAt(0);

The nextInt() then nextLine() trap

nextInt() (like nextDouble() and next()) reads the number but leaves the Enter (new-line character) in the input. A following nextLine() reads up to that new line, so it returns an empty string immediately.

As run in this study guide (input 14, Enter, Pune, Enter):
int age = sc.nextInt();
String city = sc.nextLine();
System.out.println("Age " + age + ", city [" + city + "]");
Output: Age 14, city []
The user never gets a chance to type the city.

Fixes:
1. Read strings with nextLine() before reading numbers (as in the report program below).
2. Add an extra sc.nextLine(); after nextInt() to consume the leftover new line.
3. If the string has no spaces, use next() instead of nextLine().

Worked example

(2 marks) A program reads int age = sc.nextInt(); then String city = sc.nextLine(); The city is always blank. Explain and fix.

Try it first, then show the solutionSolution
  1. nextInt() leaves the new-line character in the input; nextLine() reads it and returns an empty string - 1 mark.
  2. Fix: add sc.nextLine(); after nextInt(), or read the city before the age - 1 mark.

Answer: nextInt() reads 14 but leaves the Enter key's new line in the buffer, which nextLine() reads at once, giving an empty string. Insert sc.nextLine(); after reading the age (or read the city first).

Types of errors: syntax, runtime and logical

1. Syntax errors (compile-time errors): violations of the grammar rules of Java, detected by the compiler; the program does not compile until they are corrected.
Examples: a missing semicolon (';' expected), a misspelt keyword (Int for int), unmatched braces, using a variable that has not been declared (cannot find symbol), a missing import for Scanner.

2. Runtime errors: the program compiles, but an error occurs while it is running and the program stops abnormally (an exception).
Examples (as run in this study guide):

  • Dividing an integer by zero: java.lang.ArithmeticException: / by zero.
  • Typing text when nextInt() expects a number: java.util.InputMismatchException.

3. Logical errors: the program compiles and runs without stopping but gives wrong results, because the logic or formula is wrong. The compiler cannot detect them; they are found by testing with known answers.
Example (as run): int a = 10, b = 20; System.out.println(a + b / 2); prints 20 instead of the average 15, because / is done before +. Correct: (a + b) / 2.

Debugging: correcting errors. Test programs with simple values whose answers you know.

Worked example

(2 marks) Classify each error: (i) int x = 5 (no semicolon); (ii) average = a + b / 2; (iii) entering 'ten' for nextInt().

Try it first, then show the solutionSolution
  1. (i) syntax error; (ii) logical error - 1 mark.
  2. (iii) runtime error (InputMismatchException) - 1 mark.

Answer: (i) Syntax (compile-time) error. (ii) Logical error: it runs but gives the wrong average. (iii) Runtime error: InputMismatchException stops the program.

Comments

Comments are notes in the program for human readers; the compiler ignores them (they are non-executable).

1. Single-line comment: begins with // and continues to the end of that line.
int total = m1 + m2 + m3; // sum of marks

2. Multi-line comment: begins with /* and ends with */; it can span several lines.
/* Program to prepare a student report
Written for ICSE Class IX */

Uses: explaining the purpose of the program and of difficult steps; recording the author and date; temporarily switching off a line while testing.

Good practice: comment what each section does (input, processing, output), not every obvious line. (Java also has documentation comments beginning /** for generating help pages; they are not required in Class IX.)

Worked example

(2 marks) Distinguish between single-line and multi-line comments with an example of each.

Try it first, then show the solutionSolution
  1. Single-line: starts with //, ends at the end of the line, e.g. // sum of marks - 1 mark.
  2. Multi-line: between /* and */, can cover many lines - 1 mark.

Answer: A single-line comment starts with // and lasts to the end of the line: // sum of marks. A multi-line comment is enclosed between /* and */ and can run over several lines: /* Program to prepare a student report */.

Data Processing in Java 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.

Three ways to give data

Suppose a coffee machine has a fixed default cup size, lets you choose 'strong' or 'mild' when you press start, and asks 'Sugar? Y/N' halfway through brewing.

Match these to initialisation, parameters and input.

Try it first, then show the solutionSolution
  1. Fixed default cup size: built in beforehand, like initialisation.
  2. Choice given when starting: like a parameter passed when a method is called.
  3. Question asked during brewing: like Scanner input during execution.

Answer: Default cup size = initialisation; strength chosen at start = parameter; sugar asked during brewing = input stream with Scanner.

Memory hook: Before, at the start, during.

Logical error

Imagine a calculator app that shows 20 as the average of 10 and 20, without any error message.

What kind of error is this and how would you find it?

Try it first, then show the solutionSolution
  1. The app runs and gives an answer, so it is not a syntax or runtime error.
  2. The answer is wrong: a logical error, probably a + b / 2 instead of (a + b) / 2.
  3. Test with values whose answer you know.

Answer: A logical error: the formula ignores precedence. It is found only by testing with known values and correcting the formula to (a + b) / 2.

Memory hook: Runs fine, answer wrong: logic.

Runtime error

Suppose an online form asks for your age and you type 'fourteen' in words, and the page crashes.

Which kind of error is this in a Java program, and what is its name?

Try it first, then show the solutionSolution
  1. The program compiled and started, so it is not a syntax error.
  2. It stopped while running because the input could not be read as a number.
  3. Java reports InputMismatchException.

Answer: A runtime error: nextInt() cannot convert 'fourteen' to an int and throws java.util.InputMismatchException, stopping the program.

Memory hook: Crashes while running: runtime.

Topics in this chapter

Data Processing in Java: syntax and key facts

Data sources
Initialisation (before execution); parameters (at execution); Scanner input (during execution)
Syllabus wording.
Scanner methods
nextShort(), nextInt(), nextLong(), nextFloat(), nextDouble(), next(), nextLine(), next().charAt(0)
Match method to variable type.
Errors
Syntax: found by compiler; runtime: program stops while running; logical: wrong output, no message
/ by zero; InputMismatchException.
Comments
// single line; /* multi-line */
Non-executable.

How the school exam asks Data Processing in Java

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

Question typeHow it is askedMethod
MCQ (1 mark)Scanner method for a double or a sentence; default package; type of a given error.Match type to method; java.lang is default.
Short answer (2 marks)next() vs nextLine(); initialisation vs input; syntax vs logical error; comments.Two clear contrasting points with code.
Output and debugging (2 marks)What is stored by each Scanner call for given input? Why is a string blank?Track the input tokens and the leftover new line.
Program (15 marks)Accept data of several types and process it (report cards, bills, conversions).Prompt before each input; correct Scanner method per type; comments for each section.

Tricks to remember Data Processing in Java

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

  • Before - At - During

    Initialisation before, parameter at the start, Scanner during.

    Use it when: Three ways of supplying data.

  • SRL errors

    Syntax: Spelling and grammar; Runtime: Running crash; Logical: Looks fine, wrong answer.

    Use it when: Types of errors.

  • next stops at space, nextLine stops at Enter

    next() = one word; nextLine() = whole line.

    Use it when: Choosing string input.

Data Processing in Java: exam-level solved questions

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

Example 1: Reading a sentence · 1 mark · MCQExam level

Which Scanner method reads a full name such as 'Riya Sen' in one go?
(a) next()
(b) nextLine()
(c) nextChar()
(d) nextString()

Try it first, then show the solutionSolution
  1. next() stops at the space; nextChar() and nextString() do not exist.
  2. nextLine() reads the whole line.

Answer: (b) nextLine()

Example 2: Assertion and reason: logical errors · 1 mark · Assertion-reasonHarder exam level

Assertion (A): The compiler cannot detect logical errors.
Reason (R): A program with a logical error follows Java's grammar rules and runs, but gives wrong results.
(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. The compiler checks syntax only.
  2. Wrong logic is still valid syntax; R explains A.

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

Example 3: Trace Scanner input · 2 marks · Short answerHOTS / competency

The user types:
120 45000 9876543210 2.5 3.14159 Good morning
New Delhi India
Yes
State what is stored by:
String w = sc.next(); String rest = sc.nextLine(); String line = sc.nextLine(); char c = sc.next().charAt(0);
(after the five numbers have been read).

Try it first, then show the solutionSolution
  1. next() reads "Good"; nextLine() reads the rest of the first line: " morning" (leading space).
  2. The next nextLine() reads "New Delhi India"; next().charAt(0) reads "Yes" and takes 'Y'.

Answer: w = "Good", rest = " morning", line = "New Delhi India", c = 'Y'

Example 4: Classify errors · 2 marks · Very short answerHarder exam level

Name the type of error and the message Java gives: (i) System.out.println(n / zero); where zero is 0; (ii) a program prints 20 as the average of 10 and 20.

Try it first, then show the solutionSolution
  1. (i) Runtime error: java.lang.ArithmeticException: / by zero.
  2. (ii) Logical error: no message; the formula a + b / 2 is wrong.

Answer: (i) Runtime error; Java stops with ArithmeticException: / by zero. (ii) Logical error; there is no message, the output is simply wrong (use (a + b) / 2).

Example 5: next() versus nextLine() · 2 marks · Very short answerExam level

Distinguish between next() and nextLine().

Try it first, then show the solutionSolution
  1. next() reads a single word (token), stopping at a space or new line.
  2. nextLine() reads all remaining characters on the current line, including spaces.

Answer: next() returns the next word only, stopping at whitespace; nextLine() returns everything up to the end of the current line, including spaces.

Example 6: Fix the blank city · 2 marks · Very short answerHarder exam level

Rewrite so that the city is read correctly:
int age = sc.nextInt();
String city = sc.nextLine();

Try it first, then show the solutionSolution
  1. nextInt() leaves the new line; consume it.
  2. Add sc.nextLine(); between the two statements.

Answer: int age = sc.nextInt();
sc.nextLine(); // consume the leftover new line
String city = sc.nextLine();

Example 7: Student report program · 15 marks · Long answerHarder exam level

Write a program to accept a student's name (may contain spaces), roll number, section letter and marks in three subjects (decimals allowed). Print the name, roll number and section on one line, then the total and percentage (out of 300). Add comments.

Try it first, then show the solutionSolution
  1. // Student report: input of different types with the Scanner class
    import java.util.*;
    class Report
    {
    public static void main(String args[])
    {
    Scanner sc = new Scanner(System.in);
  2. System.out.print("Name: ");
    String name = sc.nextLine(); // whole line, spaces allowed
    System.out.print("Roll number: ");
    int roll = sc.nextInt();
    System.out.print("Section: ");
    char sec = sc.next().charAt(0); // first character of the next word
  3. System.out.print("Marks in three subjects: ");
    double m1 = sc.nextDouble();
    double m2 = sc.nextDouble();
    double m3 = sc.nextDouble();
    double total = m1 + m2 + m3;
    double percent = total / 300 * 100;
  4. System.out.println();
    System.out.println("Student : " + name + " (Roll " + roll + ", Section " + sec + ")");
    System.out.println("Total : " + total);
    System.out.println("Percent : " + percent);
    }
    }
  5. The name is read first with nextLine(), avoiding the nextInt()-then-nextLine() trap. Trace: 78 + 85.5 + 90 = 253.5; 253.5 / 300 × 100 = 84.5.

Answer: Sample run (as run; inputs Riya Sen, 27, B, 78 85.5 90):
Name: Riya Sen
Roll number: 27
Section: B
Marks in three subjects: 78 85.5 90

Student : Riya Sen (Roll 27, Section B)
Total : 253.5
Percent : 84.5

Case-study practice (Section B style)

Read the situation, then answer every part. In a school exam set on the board pattern this is a 7-mark question split into 2 + 3 + 2 marks.

A fee calculator that misbehaves

Imagine Dev writes a program that asks for the number of months (int) and then the student's full name, and divides the annual fee by the number of months to get the monthly fee. Testers report three problems: (1) the name is always blank; (2) typing 'twelve' for the number of months makes the program crash; (3) entering 0 months makes it crash with a different message.

  1. (i) · 2 marks

    Explain problem (1) and give a fix.

    Answer

    Answer: nextInt() leaves the new line in the input, so the following nextLine() reads an empty string. Fix: add sc.nextLine(); after nextInt(), or read the name first.

    1 mark cause, 1 mark fix.

  2. (ii) · 3 marks

    Name the errors in problems (2) and (3), and their type.

    Answer

    Answer: (2) InputMismatchException: the word 'twelve' cannot be read as an int by nextInt(). (3) ArithmeticException: / by zero (integer division by 0). Both are runtime errors.

    1 mark each exception, 1 mark type.

  3. (iii) · 2 marks

    Is a program that gives the wrong monthly fee, because Dev typed fee * months, a syntax, runtime or logical error? How would testing reveal it?

    Answer

    Answer: A logical error. Testing with a known case, e.g. fee 12,000 for 12 months, should give 1,000; getting 144,000 reveals the wrong operator.

    1 mark type, 1 mark testing.

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.

Distinguish between a syntax error and a logical error. (2 marks) (2 marks)

StepMarks
Syntax: breaks Java's rules; detected by the compiler; program does not compile (e.g. missing ;).1
Logical: program runs but gives wrong output; not detected by the compiler (e.g. a + b / 2 for an average).1

Program: student report with Scanner input of several types. (15 marks) (15 marks)

StepMarks
import, class, main() and Scanner object.2
Prompts before each input.2
Correct methods: nextLine() for name, nextInt() for roll, next().charAt(0) for section, nextDouble() for marks.5
Total and percentage calculated correctly.3
Labelled output and comments.3

Where students lose marks in Data Processing in Java

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

  • Mistake: Using a non-existent method

    Guessing method names.

    Wrong working

    char c = sc.nextChar();

    Right working

    char c = sc.next().charAt(0);

    Do this: Learn the eight methods listed in the syllabus exactly.

    Usually costs: 1 to 2 marks.

  • Mistake: Method does not match the variable type

    Copying nextInt() for every input.

    Wrong working

    double price = sc.nextInt(); (decimals rejected)

    Right working

    double price = sc.nextDouble();

    Do this: Choose the method that matches the declared type.

    Usually costs: 1 mark per input.

  • Mistake: Blank strings after numbers

    The leftover new line.

    Do this: Read strings first, or add sc.nextLine(); after nextInt().

    Usually costs: 1 to 2 marks.

  • Mistake: Calling division by zero a syntax error

    Error types confused.

    Do this: It compiles; the crash happens while running: a runtime error.

    Usually costs: 1 mark.

Practice questions on Data Processing 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 · MCQExam level

    Which package is imported by default in every Java program?
    (a) java.util
    (b) java.io
    (c) java.lang
    (d) java.net

    Hint

    System, String, Math.

    Answer

    (c) java.lang

  2. Q2 · 1 mark · MCQExam level

    To read a char with Scanner, we use:
    (a) sc.nextChar()
    (b) sc.next().charAt(0)
    (c) sc.nextLine(0)
    (d) sc.charAt()

    Hint

    No nextChar().

    Answer

    (b) sc.next().charAt(0)

  3. Q3 · 2 marks · Very short answerHarder exam level

    Write statements to accept (i) a long mobile number, (ii) a float price.

    Hint

    nextLong, nextFloat.

    Answer

    (i) long mobile = sc.nextLong();
    (ii) float price = sc.nextFloat();

  4. Q4 · 2 marks · Very short answerHarder exam level

    What are parameters? How does BlueJ obtain values for a method with parameters?

    Hint

    At execution.

    Answer

    Parameters are variables in a method's header that receive values when the method is called, so data is supplied at the time of execution. When such a method is run in BlueJ, a dialog box asks the user to enter the values.

  5. Q5 · 2 marks · Very short answerHarder exam level

    Give the output: int a = 10, b = 20; System.out.println("Logical error: " + (a + b / 2)); System.out.println("Correct: " + (a + b) / 2);

    Hint

    Precedence.

    Answer

    Logical error: 20
    Correct: 15

  6. Q6 · 2 marks · Short answerHOTS / competency

    Why is a syntax error easier to correct than a logical error?

    Hint

    Who finds it.

    Answer

    The compiler finds a syntax error and reports the line and the problem, so it can be located at once. A logical error produces no message; the programmer must notice the wrong output and trace the logic to find it.

  7. Q7 · 3 marks · Short answerHOTS / competency

    Identify the type of error: (i) Systm.out.println(x); (ii) using sc.nextInt() and entering 4.5; (iii) area = 2 * l * b; for a rectangle's area.

    Hint

    Compiler, crash, wrong answer.

    Answer

    (i) Syntax error (cannot find symbol Systm). (ii) Runtime error (InputMismatchException). (iii) Logical error (area doubled).

  8. Q8 · 15 marks · Long answerHarder exam level

    Write a program to accept the name of an item (may contain spaces), its price (double) and quantity (int), and print the item name and the amount payable.

    Hint

    Read the name first.

    Answer

    import java.util.*;
    class Purchase
    {
    public static void main(String args[])
    {
    Scanner sc = new Scanner(System.in);
    System.out.print("Item: ");
    String item = sc.nextLine();
    System.out.print("Price: ");
    double price = sc.nextDouble();
    System.out.print("Quantity: ");
    int qty = sc.nextInt();
    System.out.println(item + " : Rs " + price * qty);
    }
    }
    Sample run (as run; inputs Steel bottle, 249.5, 2):
    Item: Steel bottle
    Price: 249.5
    Quantity: 2
    Steel bottle : Rs 499.0

  9. Q9 · 2 marks · Very short answerExam level

    Give two uses of comments in a program, and write one comment of each type.

    Hint

    Explain; switch off.

    Answer

    Uses: to explain what a program or a step does, and to temporarily disable a line while testing. // calculates the total /* Report program
    Class IX */

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.Scanner method for a whole line?Show answer

    nextLine()

  2. 2.Exception when text is typed for nextInt()?Show answer

    InputMismatchException

  3. 3.Error type found by the compiler?Show answer

    Syntax (compile-time) error.

  4. 4.Package containing Scanner?Show answer

    java.util

  5. 5.Symbols for a multi-line comment?Show answer

    /* ... */

  6. 6.Data supplied before execution is called?Show answer

    Initialisation.

Best order to study it

  1. Learn initialisation, parameters and input with an example of each.
  2. Learn packages and which ones hold System, Scanner and Math.
  3. Learn the eight Scanner methods and practise reading mixed input.
  4. Learn the nextInt()-nextLine() trap and its fixes.
  5. Learn the three types of errors with examples; then comments.

Quick revision checklist

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

  • Initialisation: before execution; parameters: at execution; Scanner: during execution.
  • Package: group of related classes; java.lang is default; Scanner is in java.util.
  • nextShort, nextInt, nextLong, nextFloat, nextDouble, next (word), nextLine (line), next().charAt(0) (char).
  • nextLine() after nextInt() reads an empty line: consume it first.
  • Syntax (compiler), runtime (crash: / by zero, InputMismatchException), logical (wrong answer).
  • Comments: // single line; /* */ multi-line; ignored by the compiler.

Data Processing in Java: frequently asked questions

Can I read several numbers on one line?

Yes. Scanner splits input at spaces and new lines, so 78 85.5 90 typed on one line can be read by three nextDouble() calls.

Do I need try-catch to handle InputMismatchException?

No. Exception handling is not in the Class IX syllabus; you only need to recognise such errors as runtime errors.

Is a warning the same as an error?

No. A warning points out something suspicious but the program still compiles; an error stops compilation.

Based on: CISCE ICSE 2028 Computer Applications (86) syllabus (Classes IX and X); CISCE Regulations for ICSE Examination Year 2028