Sample Question Class Ix 2025
Sample Question Class Ix 2025
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[]
—————————————————————————————————————-
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.
double fine = 0;
import java.util.Scanner;
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);
}
}
double sum = 0;
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;
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;
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;
scanner.close();
}
}