0% found this document useful (0 votes)
27 views11 pages

Sample Question Class Ix 2025

Uploaded by

rohitshaw697
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
27 views11 pages

Sample Question Class Ix 2025

Uploaded by

rohitshaw697
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

ICSE Answer Paper – Sample Paper

Class IX
—————————————————————————————————————-
COMPUTER APPLICATIONS
(Theory)
(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.
The intended marks for questions or parts of questions are given in brackets[]
—————————————————————————————————————-

SECTION A (40 Marks)


Answer all questions from this Section
[20]

1. Which of the following is not a primitive data type in Java?


a) int
b) float
c) String
d) char
Answer: c) String
2. Which keyword is used to create a class in Java?
a) class
b) new
c) object
d) create
Answer: a) class
3. Which of the following is the default value of a boolean in Java?
a) 0
b) true
c) false
d) null
Answer: c) false
4. What is the size of the double data type in Java?
a) 4 bytes
b) 8 bytes
c) 16 bytes
d) 2 bytes
Answer: b) 8 bytes
5. Which operator is used to compare two values in Java?
a) =
b) ==
c) ===
d) !=
Answer: b) ==
6. What is the correct way to declare a constant in Java?
a) const int x = 10;
b) final int x = 10;
c) static int x = 10;
d) constant int x = 10;
Answer: b) final int x = 10;
7. What does JVM stand for?
a) Java Virtual Machine
b) Java Verified Machine
c) Java Variable Machine
d) Java Value Machine
Answer: a) Java Virtual Machine
8. Which of the following is not a valid keyword in Java?
a) void
b) static
c) private
d) define
Answer: d) define
9. Which method is used to get user input in Java?
a) System.in.read()
b) nextInt()
c) read()
d) getInput()
Answer: b) nextInt()
10. What is the extension of a compiled Java file?
a) .java
b) .class
c) .exe
d) .txt
Answer: b) .class
11. Which keyword is used to create an object in Java?
a) create
b) new
c) object
d) class
Answer: b) new
12. Which of the following loops executes at least once?
a) for
b) while
c) do-while
d) nested loop
Answer: c) do-while
13. What is the syntax of an if statement in Java?
a) if (condition) { statements; }
b) if condition { statements; }
c) if condition: { statements; }
d) if { condition statements; }
Answer: a) if (condition) { statements; }
14. What is the purpose of the continue statement in Java?
a) To exit the loop
b) To skip the current iteration
c) To end the program
d) To return a value
Answer: b) To skip the current iteration
15. What does the else block do in an if-else statement?
a) Executes if the if condition is false
b) Executes if the if condition is true
c) Executes before the if condition
d) None of the above
Answer: a) Executes if the if condition is false
16. Which of these is not a valid loop in Java?
a) for
b) while
c) do-while
d) repeat-until
Answer: d) repeat-until
17. What is the output of the following code?
int x = 5;
if (x > 3) {
System.out.println("Yes");
}
a) Yes
b) No
c) Error
d) None of the above
Answer: a) Yes
18. What does the break statement do in Java?
a) Exits a loop or switch case
b) Skips to the next iteration
c) Ends the program
d) None of the above
Answer: a) Exits a loop or switch case
19. Which operator is used for logical AND in Java?
a) &&
b) ||
c) &
d) |
Answer: a) &&
20. What is the output of the following code?
for (int i = 0; i < 3; i++) {
System.out.print(i);
}
a) 0 1 2
b) 1 2 3
c) 0 1 2 3
d) 1 2
Answer: a) 0 1 2
Question 2(i)
Rewrite the following code using single if statement.
if(code=='g')
System.out.println("GREEN");
else if(code=='G')
System.out.println("GREEN");
Answer
The code can be rewritten using a single if statement as follows:
if(code == 'g' || code == 'G')
System.out.println("GREEN");
Explanation:
• The logical OR operator (||) is used to check if code is either 'g' or 'G'.
• If either condition is true, the statement System.out.println("GREEN"); will execute. This simplifies
the multiple if-else blocks into a single if statement.

Question 2(ii)
Evaluate the given expression when the value of a=2 and b=3
b*=a++ - ++b + ++a;
System.out.println("a= "+a);
System.out.println("b= "+b);
Answer
a = 4, b = 6
Explanation:
The given expression is evaluated as follows:
b*=a++ - ++b + ++a
b = b * (a++ - ++b + ++a) [a=2, b=3]
b = 3 * (2 - 4 + 4) [a=4, b=4]
b=3*2
b=6
Question 2(iii)
A student executes the following program segment and gets an error. Identify the statement which has an
error, correct the same to get the output as WIN.
boolean x = true;
switch(x)
{
case 1: System.out.println("WIN"); break;
case 2: System.out.println("LOOSE");
}
Answer
Statement having the error is:
boolean x = true;
Corrected code:
int x = 1; // Change boolean to int
switch(x)
{
case 1: System.out.println("WIN"); break;
case 2: System.out.println("LOOSE");
}
Explanation:
The error occurs because the switch statement in Java does not support the boolean data type.
A switch expression must be one of the following types:
• int, byte, short, char, String, or an enum.
Replacing boolean x = true; with int x = 1; ensures that the switch statement now uses a valid data type
(int). Assigning x = 1 makes the case 1 to execute printing WIN as the output.
Question 2(iv)
Write the Java expression for x3+y3x+y
Answer
The Java expression for the given mathematical expression can be written as:
Math.cbrt(x) + Math.sqrt(y);

Question 2(v)
How many times will the following loop execute? Write the output of the code:
int x=10;
while (true){
System.out.println(x++ * 2);
if(x%3==0)
break;
}
Answer
The loop executes two times.
Output
20
22
Explanation:
Step-by-Step Execution of the Code
Initial Value of x:
x = 10
Iteration 1:
System.out.println(x++ * 2);
• x++ → Use the current value of x (10), then increment x to 11.
• Output: 10 * 2 = 20
if (x % 3 == 0):
• x = 11, so 11 % 3 = 2 → Condition is false.
Iteration 2:
System.out.println(x++ * 2);
• x++ → Use the current value of x (11), then increment x to 12.
• Output: 11 * 2 = 22
if (x % 3 == 0):
• x = 12, so 12 % 3 = 0 → Condition is true.
break;
• The break statement exits the loop.
Question 2(vi)
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(vii)
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(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
Iteration x y Remarks
2 50 Initial values
1 4 47 ++x ⟹ x = 3
y = y - x++ ⟹ y = 50 - 3
⟹ y = 47
x=4
2 6 42 ++x ⟹ x = 5
y = y - x++ ⟹ y = 47 - 5
⟹ y = 42
x=6
3 8 35 ++x ⟹ x = 7
y = y - x++ ⟹ y = 42 - 7
⟹ y = 35
x=8
4 10 26 ++x ⟹ x = 9
y = y - x++ ⟹ y = 35 - 9
⟹ y = 26
x = 10
5 12 16 ++x ⟹ x = 11
y = y - x++ ⟹ y = 26 - 11
⟹ y = 15
x = 12
Loop terminates
Question 2(ix)
What will be the output of the following code?
int m=2
int n=15;
for(int i=1;i<5;i++)
m++; - - n;
System.out.println("m="+m);
System.out.println("n="+n);
Ans:
m=6
n = 11

Question 2(x)
What is the difference between if and switch?
if else if switch-case
if else if can test for any Boolean expression like less switch-case can only test if the expression is
than, greater than, equal to, not equal to, etc. equal to any of its case constants.
if else if can use different expression involving unrelated switch-case statement tests the same
variables in its different condition expressions. expression against a set of constant
values.

SECTION B (60 MARKS)


Attempt any 4 programs
Question 3 A library charges fine for books returned late.
Following are the fines:
first five days 40 paisa per day
Six to ten days 65 paisa per day
above 10 days 80 paisa per day.
Design a program to calculate the fine assuming that a book is returned N days late.
import java.util.Scanner;

public class LibraryFineCalculator {


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

// Input: Number of days the book is returned late


System.out.print("Enter the number of days the book is returned late: ");
int daysLate = scanner.nextInt();

double fine = 0;

// Calculate fine based on the number of days late


if (daysLate <= 5) {
fine = daysLate * 0.40; // 40 paisa per day for first 5 days
} else if (daysLate <= 10) {
fine = (5 * 0.40) + ((daysLate - 5) * 0.65); // First 5 days + next 6-10 days
} else {
fine = (5 * 0.40) + (5 * 0.65) + ((daysLate - 10) * 0.80); // First 5 days + next 5 days + above 10 days
}

// Output: Display the total fine


System.out.printf("The total fine is Rs. %.2f%n", fine);
}
}

Question 4 Generate the pattern

import java.util.Scanner;

public class DiamondPattern {


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

// Input: Number of rows for the top half of the diamond


System.out.print("Enter the number of rows for the diamond pattern: ");
int rows = scanner.nextInt();

// Print the upper half of the diamond


for (int i = 1; i <= rows; i++) {
// Print spaces
for (int j = rows; j > i; j--) {
System.out.print(" ");
}
// Print stars
for (int k = 1; k <= (2 * i - 1); k++) {
System.out.print("*");
}
System.out.println();
}

// Print the lower half of the diamond


for (int i = rows - 1; i >= 1; i--) {
// Print spaces
for (int j = rows; j > i; j--) {
System.out.print(" ");
}
// Print stars
for (int k = 1; k <= (2 * i - 1); k++) {
System.out.print("*");
}
System.out.println();
}
}
}
Sample Output:
Case 1: Input = 4

Question 5 WAP to accept a number and check whether the number is perfect number or not. A number
is called perfect number, if the sum of all factors (except number itself) of the number is equal to
that number. (For e.g. 6 is a perfect number. Factors are 1, 2 & 3 and the sum is 1+2+3 = 6.)
import java.util.*;
class Perfect
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
int n,i,s=0;
System.out.println("Enter a Number ");
n=sc.nextInt():
for(i=1;i<n;i++)
{
if(n%i==0)
s=s+i;
}
if(s==n)
System.out.println("Perfect Number "+n);
else
System.out.println("Not Perfect Number "+n);
}
}

Question 6 Find the sum of the series.


S = (X+1)2+(X+2)3+(X+3)4+(X+4)5+…………… +(X+N)N+1
import java.util.Scanner;

public class SeriesSum {


public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
// Input: Values of X and N
System.out.print("Enter the value of X: ");
int X = scanner.nextInt();
System.out.print("Enter the value of N: ");
int N = scanner.nextInt();

double sum = 0;

// Calculate the series sum


for (int i = 1; i <= N; i++) {
sum += Math.pow(X + i, i + 1); // (X + i)^(i + 1)
}

// Output: Display the sum of the series


System.out.printf("The sum of the series is: %.2f%n", sum);
}
}

Question 7 The volume of solids, viz. cuboid, cylinder and cone can be calculated by the Formula:
1. Volume of a cuboid: (v = l × b × h)
2. Volume of a cylinder: (v = π× r²× h)
3. Volume of a cone: (v = 1/3× π × r²× h) (π = 22/7)
Using a switch case statement, write a program to find the volume of different solids by taking suitable
variables and data types.
import java.util.Scanner;

public class VolumeCalculator {


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

// Input: Choose the solid type


System.out.println("Choose the solid to calculate volume:");
System.out.println("1. Cuboid");
System.out.println("2. Cylinder");
System.out.println("3. Cone");
System.out.print("Enter your choice (1/2/3): ");
int choice = scanner.nextInt();

double volume = 0; // Variable to store the volume result


double l, b, h, r; // Variables for dimensions

switch (choice) {
case 1: // Volume of a cuboid
System.out.print("Enter the length of the cuboid: ");
l = scanner.nextDouble();
System.out.print("Enter the breadth of the cuboid: ");
b = scanner.nextDouble();
System.out.print("Enter the height of the cuboid: ");
h = scanner.nextDouble();
volume = l * b * h;
System.out.println("The volume of the cuboid is: " + volume);
break;

case 2: // Volume of a cylinder


System.out.print("Enter the radius of the cylinder: ");
r = scanner.nextDouble();
System.out.print("Enter the height of the cylinder: ");
h = scanner.nextDouble();
volume = (22.0 / 7) * r * r * h; // Using π = 22/7
System.out.println("The volume of the cylinder is: " + volume);
break;

case 3: // Volume of a cone


System.out.print("Enter the radius of the cone: ");
r = scanner.nextDouble();
System.out.print("Enter the height of the cone: ");
h = scanner.nextDouble();
volume = (1.0 / 3) * (22.0 / 7) * r * r * h; // Using π = 22/7
System.out.println("The volume of the cone is: " + volume);
break;

default:
System.out.println("Invalid choice. Please select 1, 2, or 3.");
break;
}

scanner.close();
}
}
Question 8 A special two-digit number is such that when the sum of its digits is added to the product of
its digits, the result is equal to the original two-digit number.
Example: Consider the number 59.
Sum of digits = 5 + 9 = 14
Product of digits = 5 * 9 = 45
Sum of the sum of digits and product of digits = 14 + 45 = 59
Write a program to accept a two-digit number. Add the sum of its digits to the product of its
digits. If the value is equal to the number input, then display the message “Special 2 – digit
number” otherwise, display the message “Not a special two-digit number”.
import java.util.Scanner;

public class SpecialTwoDigitNumber {


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

// Input: Accept a two-digit number


System.out.print("Enter a two-digit number: ");
int number = scanner.nextInt();

// Extracting the tens and ones digits


int tens = number / 10; // Tens digit
int ones = number % 10; // Ones digit

// Calculate sum and product of the digits


int sumOfDigits = tens + ones;
int productOfDigits = tens * ones;

// Calculate the sum of sum and product of digits


int result = sumOfDigits + productOfDigits;

// Check if the result equals the original number


if (result == number) {
System.out.println("Special 2-digit number");
} else {
System.out.println("Not a special two-digit number");
}

scanner.close();
}
}

You might also like