KnowledgeBoat Logo
OPEN IN APP

2024 Exam

Solved Sample Paper 1

Sample Papers ICSE Class 10 Computer Applications



Section A

Question 1(i)

If ((a > b) && (a > c)), then which of the following statement is true?

  1. a is the largest number.
  2. b is the largest number.
  3. c is the largest number.
  4. b is the smallest number.

Answer

a is the largest number.

Reason — Assuming that the given condition ((a > b) && (a > c)) is true, it implies that (a > b) and (a > c) both are true. Hence, a is greater than b and c.

Question 1(ii)

Which of the following might make the Java compiler report a syntax error in a particular line of a program?

  1. The program is typed in the wrong font.
  2. The line contains a comma(,) instead of a dot(.).
  3. It is caused by Java runtime.
  4. Program takes too long to complete.

Answer

The line contains a comma(,) instead of a dot(.)

Reason — In Java, a comma is used to separate items in a list, such as in method arguments or variable declarations. If a dot is expected (e.g., for method calls or accessing object members), and we use a comma instead, it would result in a syntax error.

Question 1(iii)

A class is :

  1. an object factory
  2. a blueprint to create objects
  3. a specification for objects
  4. All of the above

Answer

All of the above

Reason — A class is considered as an object factory as it is a blueprint to create objects and it contains specifications for objects.

Question 1(iv)

Assume x = 1 with the following code snippet:

int y = --x;

Which one of the following is true?

  1. x = 1, y = 1
  2. x = 0; y = 0
  3. x = 1; y = 0
  4. x = 0; y = 1

Answer

x = 0; y = 0

Reason — Prefix decrement operator first decrements and then uses the value. Thus, the value of x will be decremented first (making x = 0) and then the value will be assigned to y (making y = 0).

Question 1(v)

Consider the following code snippet:

float x = 8.25F;
int	y;
y = (int)x;

What are the values of x and y?

  1. x = 8.25, y = 8
  2. x = 8.0, y = 8.0
  3. x = 8, y = 8.25
  4. x = 8, y = 8

Answer

x = 8.25, y = 8

Reason — float data type can store numbers with decimal and int data type stores signed/unsigned integer values. So, x = 8.25. Then, the user is declaring an int variable y and type casting the float value x to an int and assigning it to y.

When we cast x to an int, the fractional part is truncated and the int value (8) is stored in y. Thus, y = 8.

Question 1(vi)

Parameters in method definition are called

  1. actual parameters
  2. formal parameters
  3. informal parameters
  4. void parameters

Answer

formal parameters

Reason — Parameters in method definition are called formal parameters.

Question 1(vii)

Give the output of Math.ceil(-0.6)

  1. -1.6
  2. -1.5
  3. -1.0
  4. -0.0

Answer

-0.0

Reason — Math.ceil method returns the smallest double value that is greater than or equal to the argument and is equal to a mathematical integer. Thus, Math.ceil(-0.6) returns -0.0.

Question 1(viii)

Which operator cannot be used with if-else statement?

  1. <=
  2. ||
  3. &&
  4. ? :

Answer

? :

Reason — Relational operators ( <= ) and logical operators (|| and &&) can be used to test a condition as they return boolean values. Ternary operator (? :) is used to assign a value to a variable based on a condition. Thus, it cannot be used with if-else statement.

Question 1(ix)

By default, floating literal is

  1. double
  2. float
  3. int
  4. long

Answer

double

Reason — By default, floating literal is double.

Question 1(x)

JVM converts bytecode directly into

  1. machine code
  2. another byte code
  3. high level code
  4. None of these

Answer

machine code

Reason — JVM converts bytecode directly into machine code as it is responsible for interpreting or compiling Java bytecode into machine code that is executed by the host computer's CPU.

Question 1(xi)

Which of the following statements is true?

  1. Binary search is less efficient than linear search.
  2. Binary search is more efficient than linear search.
  3. Binary search is as efficient as linear search.
  4. None of the above

Answer

Binary search is more efficient than the linear search.

Reason — Binary search is more efficient than linear search as it requires lesser number of comparisons to find an element in an array compared to linear search.

Question 1(xii)

Which element is num[9] of array num?

  1. 8th
  2. 9th
  3. 10th
  4. 11th

Answer

10th

Reason — Array index begins from 0 to size - 1. Thus, num[0] is the 1st element, num[1] is the 2nd element, num[2] is the 3rd element and so on. So, num[9] is actually the 10th element of the array.

Question 1(xiii)

What is the value returned by function compareTo( ), if the invoking string is less than the string compared?

  1. zero
  2. value less than zero
  3. value greater than zero
  4. None of the above

Answer

value less than zero

Reason — The compareTo() method compares two strings lexicographically, and returns a value based on the following logic:

if string1 > string2 the result will be a positive integer, i.e., result > 0
if string1 < string2 the result will be a negative integer, i.e., result < 0
if string1 = string2 the result will be 0, i.e., result = 0

Question 1(xiv)

............... class is used to convert a primitive data type to its corresponding object.

  1. String
  2. Wrapper
  3. System
  4. Math

Answer

Wrapper

Reason — Wrapper class is used to convert a primitive data type to its corresponding object.

Question 1(xv)

This access specifier can be accessed only by the subclass in other package or any class within the same package.

  1. protected
  2. private
  3. public
  4. default

Answer

protected

Reason — protected access specifier can be accessed only by the subclass in other package or any class within the same package.

Question 1(xvi)

Which of these data type value is returned by equals() method of string class?

  1. char
  2. int
  3. boolean
  4. All of these

Answer

boolean

Reason — equals() method checks if contents of two strings are same or not. The result is true if the contents are same otherwise it is false.

Question 1(xvii)

Assertion (A) Class initialisation is the explicit initialisation of class fields to values.
Reason (R) Each class field explicitly initialises to a value via a class field initialiser.

  1. Both Assertion (A) and Reason (R) are true and Reason (R) is a correct explanation of Assertion (A).
  2. Both Assertion (A) and Reason (R) are true and Reason (R) is not a correct explanation of Assertion (A).
  3. Assertion (A) is true and Reason (R) is false.
  4. Assertion (A) is false and Reason (R) is true.

Answer

Both Assertion (A) and Reason (R) are true and Reason (R) is a correct explanation of Assertion (A).

Reason — Assertion (A) is true as constructors are invoked at the time of instance creation which assign values to various class fields. Reason (R) is true as constructors initialize values to class fields. Thus, Reason (R) explains Assertion (A).

Question 1(xviii)

Read the following text and choose the correct answer:

Java constructor overloading is a technique in which a class can have any number of constructors that differ in parameter list. The compiler differentiates these constructors by taking into account the number of parameters in the list and their type.

Why do we use constructor overloading?

  1. To use different types of constructors.
  2. Because it's a feature provided.
  3. To initialise the object in different ways.
  4. To differentiate one constructor from another.

Answer

To initialise the object in different ways.

Reason — Constructor overloading is used to initialise the object in different ways. A user can create multiple constructors for a class with different signatures based on the number and type of arguments.

Question 1(xix)

Assertion (A) JVM is a Java interpreter loaded in the computer memory as soon as Java is loaded.
Reason (R) JVM is different for different platforms.

  1. Both Assertion (A) and Reason (R) are true and Reason (R) is a correct explanation of Assertion (A).
  2. Both Assertion (A) and Reason (R) are true and Reason (R) is not a correct explanation of Assertion (A).
  3. Assertion (A) is true and Reason (R) is false.
  4. Assertion (A) is false and Reason (R) is true.

Answer

Both Assertion (A) and Reason (R) are true and Reason (R) is not a correct explanation of Assertion (A).

Reason — Assertion (A) is true as JVM interprets the byte code and executes the Java program. Reason (R) is true as JVM is different for different platforms such as Windows, Linux, MacOS etc. Reason (R) is not a correct explanation of Assertion (A).

Question 1(xx)

String is ............... in Java.

  1. interface
  2. mutable
  3. method
  4. immutable

Answer

immutable

Reason — String is immutable in Java.

Question 2(i)

What will be the output of the following statements?

int a = 3;
System.out.println(" " + (1 + a)); 
System.out.println(" " + 1 + a);

Answer

Output
 4
 13
Explanation
  1. System.out.println(" " + (1 + a)); — In this statement, we have an expression inside the parentheses (1 + a), which is evaluated first. This expression adds 1 and the value of a, which is 3. So, (1 + a) equals 4. After that, the + operator outside the parentheses is used for string concatenation. The string " " (a space character) is concatenated with the result of (1 + a), which is 4. Therefore, the output for this line will be " 4" (a space followed by the number 4).
  2. System.out.println(" " + 1 + a); — In this statement, we have a different expression. The + operator is evaluated from left to right. So, " " + 1 is evaluated first. It concatenates the string " " with the number 1, resulting in the string " 1". Then, it concatenates this string with the value of a, which is 3. Therefore, the output for this line will be " 13" (a space followed by the numbers 1 and 3).

Question 2(ii)

Find the output of the following code.

String str = "I Love My Family";
System.out.println(Integer.toString(str.length()));
System.out.println(str.substring(12));

Answer

Output
16
mily
Explanation
  1. String str = "I Love My Family"; — In this statement, we first use the str.length() method to determine the length of the string str, which is the number of characters in the string. The length of the string "I Love My Family" is 16 characters. Then, we use Integer.toString() to convert this length to a string before printing it. So, the output of this line will be "16" as a string.
  2. System.out.println(str.substring(12)); — In this statement, we use the str.substring(12) method to extract a substring from the original string str. The parameter 12 is the starting index from which the substring should begin. In Java, string indices are zero-based, so the character at index 12 is 'm'. The substring(12) method will extract the portion of the string starting from index 12 till the end of the string. So, the output of this line will be "mily," as it is the substring that starts from the character 'm' and extends to the end of the original string.

Question 2(iii)

Write a Java statement for the following mathematical expression :

V = 13\dfrac{1}{3}πr2h

Answer

V = 1.0 / 3.0 * Math.PI * r * r * h

Question 2(iv)

Write the value of n and m after execution of the following code.

int m;
int n;
m = 5;
n = (5 * ++m) % 3;
System.out.println("n = " + n + "m =" + m);

Answer

Output
n = 0m = 6
Explanation

The statement n = (5 * ++m) % 3; is evaluated as follows:

n = (5 * ++m) % 3; [m = 5]

⇒ n = (5 * 6) % 3; [Prefix operator first increments the value and then uses it. So, m = 5 + 1 = 6 and then it is used in the expression]

⇒ n = 30 % 3;

⇒ n = 0;

So, final value of m is 6 and n is 0.

Question 2(v)

Predict the output

(a) Math.pow(3.4, 2) + 2 * Math.sqrt(64)

(b) Math.ceil(3.4) + 2 * Math.floor(3.4) + 2

Answer

(a) 27.56

(b) 12.0

Explanation

(a) Math.pow(x, y) method returns the value of x raised to the power of y. Math.sqrt() method returns the square root of an argument. Thus, the given expression is evaluated as follows:

Math.pow(3.4, 2) + 2 * Math.sqrt(64)
⇒ 11.56 + 2 * 8.0
⇒ 27.56

(b) Math.ceil() method returns the smallest double value that is greater than or equal to the argument and is equal to a mathematical integer. Math.floor() method returns the largest double value that is less than or equal to the argument and is equal to a mathematical integer. Thus, the given expression is evaluated as follows:

Math.ceil(3.4) + 2 * Math.floor(3.4) + 2
⇒ 4.0 + 2 * 3.0 + 2
⇒ 4.0 + 6.0 + 2
⇒ 12.0

Question 2(vi)

If a = 24, b = 15, find the value of:
a += b++ * 5 / a++ + b

Answer

a += b++ * 5 / a++ + b
⇒ a = a + (b++ * 5 / a++ + b) [a = 24, b = 15]
⇒ a = 24 + (15 * 5 / a++ + b) [a = 24, b = 16]
⇒ a = 24 + (15 * 5 / 24 + 16) [a = 25, b = 16]
⇒ a = 24 + (75 / 24 + 16)
⇒ a = 24 + (3 + 16)
⇒ a = 43

Hence, final value of a is 43

Question 2(vii)

Give the prototype of a function search, which receives a sentence sentc and a word wrd and returns 1 or 0.

Answer

boolean search(String sentc, String wrd)

Question 2(viii)

How many times will the following loop execute?

int x = 2, y = 50;
do
{
    ++x;
    y -= x++;
} while (x <= 10);
return y;

Answer

The given loop will execute 5 times.

Explanation
IterationxyRemarks
 250Initial values
1447++x ⟹ x = 3
y = y - x++ ⟹ y = 50 - 3
⟹ y = 47
x = 4
2642++x ⟹ x = 5
y = y - x++ ⟹ y = 47 - 5
⟹ y = 42
x = 6
3835++x ⟹ x = 7
y = y - x++ ⟹ y = 42 - 7
⟹ y = 35
x = 8
41026++x ⟹ x = 9
y = y - x++ ⟹ y = 35 - 9
⟹ y = 26
x = 10
51216++x ⟹ x = 11
y = y - x++ ⟹ y = 26 - 11
⟹ y = 15
x = 12
Loop terminates

Question 2(ix)

If int a[] = {7, 3, 4, 8, 9, 2}; what are the values of x and y?

(a) x = a[1] * a[0] + a[3]

(b) y = a.length

Answer

(a) Since array index begin from 0, the given expression is evaluated as follows:

x = a[1] * a[0] + a[3]
⟹ x = 3 * 7 + 8
⟹ x = 29

(b) length of an array is the number of elements in an array. Thus, y = 6.

Question 2(x)

Write the return types of the following library functions:

(a) isLetterOrDigit(char)

(b) replace(char, char)

Answer

(a) boolean

(b) String

Section B

Question 3

Define a class to accept a number and check whether the number is Neon or not. A number is said to be Neon if sum of the digits of the square of the number is equal to the number itself.

E.g.
Input: 9

Output:
9 * 9 = 81, 8 + 1 = 9
9 is Neon number.

import java.util.Scanner;

public class NeonNumber
{
    public static void main(String args[]) {
        Scanner in = new Scanner(System.in);
        System.out.print("Enter the number to check: ");
        int n = in.nextInt();
        int sq = n * n;
        int sqSum = 0;
        
        while (sq != 0) {
            int d = sq % 10;
            sqSum += d;
            sq /= 10;
        }
        
        if (sqSum == n)
            System.out.println("Neon Number");
        else
            System.out.println("Not a Neon Number");
    }
}
Output
BlueJ output of NeonNumber.java
BlueJ output of NeonNumber.java

Question 4

Define a class Student described as below

Data members/instance variables
name, age, m1, m2, m3 (marks in 3 subjects), maximum, average

Member methods
(i) Student (...) : A parameterised constructor to initialise the data members.

(ii) compute() : To compute the average and the maximum out of three marks.

(iii) display() : To display the name, age, marks in three subjects, maximum and average.

Write a main method to create an object of a class and call the above member methods.

import java.util.Scanner;

public class Student
{
    private String name;
    private int age;
    private int m1;
    private int m2;
    private int m3;
    private int maximum;
    private double average;

    public Student(String n, int a, int s1, 
    int s2, int s3) {
        name = n;
        age = a;
        m1 = s1;
        m2 = s2;
        m3 = s3;
    }

    public void compute() {
        average = (m1 + m2 + m3) / 3.0;
        
        maximum = Math.max(m1, m2);
        maximum = Math.max(maximum, m3);   
    }

    public void display() {
        System.out.println("Name: " + name);
        System.out.println("Age: " + age);
        System.out.println("Subject 1 Marks: " + m1);
        System.out.println("Subject 2 Marks: " + m2);
        System.out.println("Subject 3 Marks: " + m3);
        System.out.println("Maximum Marks: " + maximum);
        System.out.println("Average Marks: " + average);
    }

    public static void main(String args[]) {
        Scanner in = new Scanner(System.in);
        System.out.print("Enter name: ");
        String n = in.nextLine();
        System.out.print("Enter age: ");
        int a = in.nextInt();
        System.out.print("Enter Subject 1 Marks: ");
        int sm1 = in.nextInt();
        System.out.print("Enter Subject 2 Marks: ");
        int sm2 = in.nextInt();
        System.out.print("Enter Subject 3 Marks: ");
        int sm3 = in.nextInt();
        Student obj = new Student(n, a, sm1, 
                                    sm2, sm3);
        obj.compute();
        obj.display();
    }
}
Output
BlueJ output of Student.java

Question 5

Define a class to input 15 integer elements in an array and sort them in ascending order using the bubble sort technique.

import java.util.Scanner;

public class KboatBubbleSort
{
    public static void main(String args[]) {
        Scanner in = new Scanner(System.in);
        int n = 15;
        int arr[] = new int[n];
        
        System.out.println("Enter the elements of the array:");
        for (int i = 0; i < n; i++) {
            arr[i] = in.nextInt();
        }
        
        //Bubble Sort
        for (int i = 0; i < n - 1; i++) {
            for (int j = 0; j < n - i - 1; j++) {
                if (arr[j] > arr[j + 1]) {
                    int t = arr[j];
                    arr[j] = arr[j+1];
                    arr[j+1] = t;
                }
            } 
        }
        
        System.out.println("Sorted Array:");
        for (int i = 0; i < n; i++) {
            System.out.print(arr[i] + " ");
        }
    }
}
Output
BlueJ output of KboatBubbleSort.java

Question 6

Define a class to overload the method display as follows:

void display(): To print the following format using nested loop

5 5 5 5 5
4 5 5 5 5
3 4 5 5 5
2 3 4 5 5
1 2 3 4 5

void display(int n): To check and display if the given number is a Perfect number or not. A number is said to be perfect, if sum of the factors of the number excluding itself is equal to the original number.

E.g.
6 = 1 + 2 + 3, where 1, 2 and 3 are factors of 6 excluding itself.

import java.util.Scanner;
public class KboatMethodOverload
{
    public void display()
    {
        for (int i = 0; i < 5; i++) {
            for (int j = 5 - i; j <= 5; j++) {
                System.out.print(j + " ");
            }
            for (int k = 4 - i; k > 0; k--) {
                System.out.print("5 ");
            }
            System.out.println();
        } 
    }

    public void display(int n) {
        int sum = 0;

        for (int i = 1; i <= n / 2; i++) {
            if (n % i == 0) {
                sum += i;
            }
        }

        if (n == sum) 
            System.out.println(n + " is a perfect number");
        else
            System.out.println(n + " is not a perfect number");
    }

    public static void main(String args[]) {
        KboatMethodOverload obj = new KboatMethodOverload();
        Scanner in = new Scanner(System.in);

        System.out.println("Pattern: ");
        obj.display();

        System.out.println();
        
        System.out.print("Enter a number: ");
        int num = in.nextInt();
        obj.display(num);

    }
}
Output
BlueJ output of KboatMethodOverload.java

Question 7

Define a class to enter a sentence from the keyboard and count the number of times a particular word occurs in it. Display the frequency of the search word.

E.g.
Input : Enter the sentence:
Hello, this is wow world
Enter the word:
wow

Output:
Searched word occurs 1 times.

import java.util.Scanner;

public class KboatWordFrequency
{
    public static void main(String args[]) {
        Scanner in = new Scanner(System.in);
        System.out.print("Enter the sentence : ");
        String str = in.nextLine();
        System.out.print("Enter the word : ");
        String ipWord = in.nextLine();
        str += " ";
        String word = "";
        int count = 0;
        int len = str.length();

        for (int i = 0; i < len; i++) {
            if (str.charAt(i) == ' ') {

                if (word.equalsIgnoreCase(ipWord))
                    count++ ;

                word = "";
            }
            else {
                word += str.charAt(i);
            }
        }
        
        if (count > 0) {
            System.out.println("Searched word occurs " + count + " times.");
        }
        else {
            System.out.println("Search word is not present in sentence.");
        }
        
    }
}
Output
BlueJ output of KboatWordFrequency.java

Question 8

Define a class to accept 5 names in one array and their respective telephone numbers into a second array. Search for a name input by the user in the list. If found, display "search successful" and print the name along with the telephone number, otherwise display "Search unsuccessful: Name not enlisted".

import java.util.Scanner;

public class KboatTelephoneNos
{
    public static void main(String args[]) {
        Scanner in = new Scanner(System.in);
        int n = 5;
        String names[] = new String[n];
        String numbers[] = new String[n];
        
        for (int i = 0;  i < n; i++) {
            System.out.print("Enter Name: ");
            names[i] = in.nextLine();
            System.out.print("Enter Telephone number : ");
            numbers[i] = in.nextLine();
        }
        
        System.out.print("Enter name to be searched : ");
        String name = in.nextLine();
        
        int idx;
        for (idx = 0;  idx < n; idx++) {
            if (name.compareToIgnoreCase(names[idx]) == 0) {
                break;
            }
        }
        
        if (idx < n) {
            System.out.println("Search Successful");
            System.out.println("Name : " + names[idx]);
            System.out.println("Telephone Number : " + numbers[idx]);
        }
        else {
            System.out.println("Search Unsuccessful : Name not enlisted");
        }
    }
}
Output
BlueJ output of KboatTelephoneNos.java
BlueJ output of KboatTelephoneNos.java
PrevNext