CLASS 10 COMPUTER SCIENCE QUESTION PAPER 2024

Maximum Marks:100

Time allowed: Two hours

Answers to this Paper must be written on the paper provided separately.

You will not be allowed to write during the first 15 minutes.

This time is to be spent in reading the question paper.

The time given at the head of this Paper is the time allowed for writing the answers.
This Paper is divided into two Sections.

Attempt all questions from Section A and any four questions from Section B.

Answers to this Paper must be written on the paper provided separately.

The intended marks for questions or parts of questions are given in brackets[] .

SECTION A

(Attempt all questions from this Section.)



Question 1

(i) Consider the above picture and choose the correct statement from the following
(a) Polygon is the object and the pictures are classes
(b) Both polygon and the pictures are classes
(c) Polygon is the class and the pictures are objects
(d) Both polygon and the pictures are objects


Solution

(b) Both polygon and the pictures are classes

(ii) int x = 98; char ch = (char)x; what is the value in ch?
(a) b
(b) A
(c) B
(d) 97


Solution

(a) b

(iii) The output of the statement "CONCENTRATION".indexOf("T") is:
(a) 9
(b) 7
(c) 6
(d) -1


Solution

(c) 6

(iv) The access specifier that gives least accessibility is:
(a) package
(b) public
(c) protected
(d) private


Solution

(d) private

(v) The output of the statement "talent".compareTo("genius") is:
(a) 11
(b) -11
(c) 0
(d) 13


Solution

(d) 13

(vi) Which of the following is an escape sequence character in Java?
(a) /n
(b) \t
(c) /t
(d) //n


Solution

(b) \t

(vii) if (a>b&&b>c) then largest number is:
(a) b
(b) c
(c) a
(d) wrong expression


Solution

(c) a

(viii) What is the output of Math.ceil(5.4)+Math.ceil(4.5)?
(a) 10.0
(b) 11.0
(c) 12.0
(d) 9.0


Solution

(a) 10.0

(ix) What is the method to check whether a character is a letter or digit?
(a) isDigit(char)
(b) isLetterOrDigit()
(c) isLetterOrDigit(char)
(d) isLETTERorDIGIT(char)


Solution

(c) isLetterOrDigit(char)

(x) The extension of a Java source code file is:
(a) exe
(b) obj
(c) jvm
(d) java


Solution

(d) java

(xi) The number of bytes occupied by a character array of four rows and three columns are:
(a) 12
(b) 24
(c) 96
(3) 48


Solution

(b) 24

(xii) Which of the following data type cannot be used with switch case construct
(a) int
(b) char
(c) String
(d) double


Solution

(d) double

(xiii) Which of the following are entry controlled loops?
1. for
2. while
3. do..while
4. switch
(a) only 1
(b) 1 and 2
(c) 1 and 3
(d) 3 and 4


Solution

(b) 1 and 2

(xiv) Method which reverses a given number is:
(a) Impure method
(b) Pure method
(c) Constructor
(d) Destructor


Solution

(b) Pure method

(xv) If the name of the class is “Yellow”, what can be the possible name for its constructors?
(a) yellow
(b) YELLOW
(c) Yell
(d) Yellow


Solution

(d) Yellow

(xvi) Invoking a method by passing the objects of a class is termed as:
(a) Call by reference
(b) Call by value
(c) Call by method
(d) Call by constructor


Solution

(a) Call by reference

(xvii) The correct statement to create an object named mango of class fruit:
(a) Fruit Mango= new fruit();
(b) fruit mango = new fruit();
(c) Mango fruit = new Mango();
(d) fruit mango = new mango();


Solution

(b) fruit mango = new fruit();

(xviii) Assertion (A): Static method can access static and instance variables.
Reason (R): Static variable can be accessed only by static method.
(a) Assertion and Reason both are correct.
(b) Assertion is true and Reason is false.
(c) Assertion is false and Reason is true.
(d) Assertion and Reason both are false.


Solution

(b) Assertion is true and Reason is false.

(xix) What is the output of the Java code given below?
String color [] = {"Blue","Red","Violet"};
System.out.println
(color[2].length());
(a) 6
(b) 5
(c) 3
(d) 2


Solution

(a) 6

(xx) Which of the following mathematical methods returns only an integer?
(a) Math.ceil(n)
(b) Math.sqrt(n)
(c) Math.floor(n)
(d) Math.round(n)


Solution

(d) Math.round(n)

Question 2

(i) Write Java expression for:
|a+b|/√(a2 + b2)


Solution

((Math.abs(a+b))/
(Math.sqrt((Math.pow(a,2)
+Math.pow(b,2)))))

(ii) Evaluate the expression when the value of x = 4:
x+=x++*++x%2;


Solution

= 4 + 4 * 6 % 2
= 4 + 24 % 2
= 4 + 0
= 4

(iii) Rewrite the following do while program segment using for:
int x = 10,y=20;
do
{
x++;
y++;
}while(x<=20);
System.out.println(x*y);


Solution

int x = 10,y=20;
for (; x <= 20;x++;)
{
y++;
}
System.out.println(x*y);

(iv) What will be the output of the following code and how many times the loop will execute ?
for (x = 10; x > 20; x++)
System.out.println(x);
System.out.println(x * 2);


Solution

The loop condition x > 20 is initially false because x is initialized to 10. Therefore, the loop body will not execute at all. After the loop, x remains at its last value, which is 10. Then, System.out.println(x * 2); will print 10 * 2 = 20.
Output will be
20

(v) String s1 = "45.50"; String s2 = "54.50";
double d1=Double.parseDouble(s1);
double d2=Double.parseDouble(s2);
int x= (int)(d1+d2);
What is value of x?


Solution

100

(vi) Consider the following two-dimensional array and answer the questions given below:
int x[][]={{4,3,2}, {7,8,2}, {8,3,10}, {1,2,9}}
(a) What is the order of the array?
(b) What is the value of x[0][0]+x[2][2]?


Solution

(a) 4x3
(b) 14

(vii) Differentiate between boxing and unboxing.


Solution

Boxing Unboxing
Converts a primitive data type into an object wrapper type Converts a wrapper object back to its primitive data type

(viii) The following code to compare two strings is compiled, the following syntax error was displayed — incompatible types — int cannot be converted to boolean. Identify the statement which has the error and write the correct statement. Give the output of the program segment.
void calculate()
{
String a = "KING", b = "KINGDOM";
boolean x = a.compareTo(b);
System.out.println(x);
}


Solution

In this case, "KING".compareTo("KINGDOM") compares the two strings lexicographically.
The comparison starts from the first character of each string. The ASCII values of the characters at the first differing position are subtracted.
The first differing character in this case is 'G' in "KING" and 'D' in "KINGDOM". The ASCII value of 'G' is 71 and the ASCII value of 'D' is 68.
The difference is calculated as: 71 - 68 = 3.
Since "KING" comes before "KINGDOM" in lexicographical order, the result is negative. So, -3 is the result.

(ix) Consider the given program and answer the questions given below:
class temp
{
int a;
temp()
{
int a=10;
}
temp(int z)
{
a=z;
}
void print()
{
System.out.println(a);
}
void main()
{
temp t = new temp();
temp x = new temp(30);
t.print();
x.print();
}}
(a) What concept of OOPs is depicted in the above program with two constructors?
(b) What is the output of the method main()?


Solution

(a) function overloading
(b) 10
30

(x) Primitive data types are built in data types which are a part of the wrapper classes. These wrapper classes are encapsulated in the java.lang package. Non primitive datatypes like Scanner class are a part of the utility package for which an object needs to be created.
(a) To which package the Character and Boolean classes belong?
(b) Write the statement to access Scanner class in the program


Solution

(a) java.lang
(b) To access the Scanner class in a program, you need to import it from the java.util package. Here's the statement to import the Scanner class:
import java.util.Scanner;
After importing, you can create objects of the Scanner class to use its functionalities in your program. For example:
Scanner sc = new Scanner(System.in);

SECTION B

(Answer any four questions from this Section.)

The answers in this section should consist of the programs in either BlueJ environment or any program environment with java as the base.

Each program should be written using variable description / mnemonic codes so that the logic of the program is clearly depicted.

Flowcharts and algorithms are not required.




Question 3

DTDC a courier company charges for the courier based on the weight of the parcel, Define
a class with the following specifications;
class name: courier
Member variables: name ~ name of the customer
weight - weight of the parcel in kilograms
address — address of the recipient
bill — amount to be paid
type - 'D'- domestic, 'I'- international
Member methods:
void accept () - to accept the details using the methods of the Scanner class only.
void calculate () - to calculate the bill as per the following criteria:
Weight in Kgs     Rate/Kg
First 5 Kgs       Rs.800
Next 5 Kgs       Rs.700
Above 10 Kgs   Rs.500
An additional amount of Rs.1500 is charged if the type of the courier
is I (International)
void print () - To print the details
void main ( ) - to create an object of the class and invoke the methods

Solution:

import java.util.*; 
class Courier 
{
    String name,address;
    char type;
    double weight,bill; 
    void accept()
    { 
        Scanner sc = new Scanner(System.in); 
        System.out.println("Enter your name"); 
        name = sc.nextLine(); 
        System.out.println("Enter your address"); 
        address = sc.nextLine(); 
        System.out.println("Enter your weight"); 
        weight = sc.nextDouble();
        System.out.println("Enter the type");
        type=sc.next().charAt(0);
    } 

    void calculate() 
    {
        if(weight<=5) 
            bill+= 800; 
        else if(weight>5 && weight<=10) 
            bill+= 700; 
        else 
            bill+= 500;

        if(type=='I')
            bill+=1500;
    } 

    void print()
    { 
        System.out.println("name="+name); 

        System.out.println("address="+address); 

        System.out.println("weight="+weight); 

        System.out.println("type="+type);
        System.out.println("Amount to be Paid="+bill);
    } 

    public static void main(String[] args)
    { 
        Courier obj = new Courier(); 
        obj.accept(); 
        obj.calculate(); 
        obj.print(); 
    }
}

  
                                        

Question 4
Define a class to overload the method perform as follows:
double perform (double r, double h)- to calculate and return the value of Curved surface area of cone
CSA=πrl L= √(r2+h2)
void perform (int r, int c) - Use NESTED FOR LOOP to generate the following format
r=4,c=5
output— 
12345
12345
12345
12345
void perform (int m, int n, char ch)- to print the quotient of the division of m and n if ch is O else print the remainder of the division of m and n if ch is R

Solution:

import java.util.*;
class overload
{ 
    double perform(double r,double h)
    { 
        double pi=3.14;
        double length=Math.sqrt((r*r)+(h*h));
        return pi*r*length;
    } 

    void perform(int r,int c)
    { 
        for(int i=1;i<=r;i++)
        {
            for(int j=1;j<=c;j++)
            {
                System.out.print(j+" ");
            }
            System.out.println();
        }
    } 

    void perform(int m,int n,char ch)
    {
        if(ch=='Q')
        {
            System.out.println((int)m/n);
        }
        else if(ch=='R')
        {
            System.out.println(m%n);
        }
    }

    public static void main(String args[]) 
    {
        overload obj = new overload(); 
        System.out.println("Curved surface area of cone="+obj.perform(12.0,14.0));
        obj.perform(4,5);
        obj.perform(12,4,'Q');   
    } 
}
  
                                        

Question 5
Define a class to accept a number from user and check if it is an EvenPal number or not.
(The number is said to be EvenPal number when number is palindrome number (a number
is palindrome if it is equal to its reverse) and sum of its digits is an even number.)
Example: 121 —is a palindrome number
Sum of the digits — 1+2+1 = 4 which is an even number

Solution:

import java.util.Scanner;
class EvenPalNumber {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        System.out.print("Enter a number: ");
        int num = sc.nextInt();
        int originalNum = num,reverse = 0,sum = 0;
        while (num != 0) {
            int digit = num % 10;
            reverse = reverse * 10 + digit;
            sum += digit;
            num /= 10;
        }
        if (originalNum == reverse) {
            if (sum % 2 == 0) 
                System.out.println(originalNum + "is an EvenPal number.");
            else 
                System.out.println(originalNum + "is not an EvenPal number.");
        } else {
            System.out.println(originalNum + "is not an EvenPal number.");
        }
    }
}

                                        

Question 6
Define a class to accept values into an integer array of order 4 x 4 and check whether it is a DIAGONAL array or not. An array is DIAGONAL if the sum of the left diagonal elements equals the sum of the right diagonal elements. Print the appropriate message.
Example -
3 4 2 5
2 5 2 3
5 3 2 7
1 3 7 1
Sum of the left diagonal elements = 345+2+1=11 
Sum of the right diagonal elements = 5+42+43+1=11  
        

Solution:

import java.util.Scanner;
class DiagonalArrayCheck {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int[][] array = new int[4][4];
        System.out.println("Enter values into a 4x4 array:");
        for (int i = 0; i < 4; i++) {
            for (int j = 0; j < 4; j++) {
                array[i][j] = scanner.nextInt();
            }
        }
        System.out.println("The entered array is:");
        for (int i = 0; i < 4; i++) {
            for (int j = 0; j < 4; j++) {
                System.out.print(array[i][j] + " ");
            }
            System.out.println();
        }
        int leftDiagonalSum = 0;
        int rightDiagonalSum = 0;
        for (int i = 0; i < 4; i++) {
            leftDiagonalSum += array[i][i];
            rightDiagonalSum += array[i][3 - i];
        }
        if (leftDiagonalSum == rightDiagonalSum) {
            System.out.println("The array is a DIAGONAL array.");
        } else {
            System.out.println("The array is not a DIAGONAL array.");
        }
    }
}

  
                                        

Question 7
Define a class pin code and store the given pin codes in a single dimensional array. Sort these pin codes in ascending order using the Selection Sort technique only. Display the sorted array.
110061, 110001, 110029, 110023, 110055, 110006, 110019, 110033 
        

Solution:



import java.util.*;
class Pincode
{
    public static void main(String args[])
    {
        int pinCodes[]={110061, 110001, 110029, 110023, 110055, 110006, 110019, 110033 };
        System.out.println("Original Pincodes array is :");  
        for(int i=0; i < pinCodes.length; i++) {  
            System.out.print(pinCodes[i]+ "  ");  
        }

        for(int i= 0; i < (pinCodes.length)-1; i++) 
        {
            int index = i;
            for(int j= i+1; j < pinCodes.length; j++) 
            {
                if(pinCodes[j] < pinCodes[index])
                {
                    
                    index = j; 
                }  
            } 
            int temp = pinCodes[i];  
            pinCodes[i] = pinCodes[index];  
            pinCodes[index] = temp;
        }
        System.out.println("\nNow the PinCodes Array after Sorting is :");  
        for(int i=0; i < pinCodes.length; i++) 
        {  
            System.out.print(pinCodes[i]+ "  ");  
        }  
    }
}
  
                                        

Question 8
Define a class to accept the gmail id and check for its validity.
A gmail id is valid only if it has:
→ @
→ .(dot)
→ gmail
→ com
Example: icse2024@gmail.com is a valid gmail id. 
        

Solution:


import java.util.*;
    class Format
    {
        public static void main(String args[])
        {
            String id;
            Scanner sc=new Scanner(System.in);
            id=sc.nextLine();
            if(!id.contains("@")|| !id.contains(".")|| !id.contains("gmail")|| !id.contains("com"))
            {
                System.out.println("Gmail id is not valid");
            }
            else
            {
                System.out.println("Gmail id is valid");
            }
        }
    }                    
     
  
                                        

Contact Us

REACH US

SERVICES

  • CODING
  • ON-LINE PREPARATION
  • JAVA & PYTHON

ADDRESS

B-54, Krishna Bhawan, Parag Narain Road, Near Butler Palace Colony Lucknow
Contact:+ 919839520987
Email:info@alexsir.com