ST.
JOSEPH'S SCHOOL
BHAGALPUR
COMPLETE
SOLUTIONS
Computer Applications · Class IX · Annual Examination 2025–26
EXAM DATE FULL MARKS TIME SECTIONS
17 / 02 / 2026 100 2 Hours A (40M) + B (60M)
SECTION A · SECTION B · ALL PROGRAMS VERIFIED
SECTION A — 40 MARKS Attempt All Questions
Q1 Choose the Correct Answer — MCQ [20 Marks]
i) The act of using essential features without background details (b) abstraction
is called __.
Abstraction hides implementation details, exposing only essential functionality to the user.
ii) Procedure oriented programming gives importance to __. (c) Instructions and data
POP revolves around functions (instructions) and the data they operate on — both are equally central.
iii) Java applications __. (c) are platform independent
Java compiles to bytecode which runs on the JVM, making programs run on any OS without recompilation.
iv) A program that translates high-level code to machine code is (a) compiler
called __.
A compiler translates the entire source program at once into machine code. A JVM uses an interpreter/JIT internally.
v) __ represents a real-world entity with characteristics and (b) An object
behaviour.
An object is an instance of a class that holds state (attributes) and behaviour (methods).
vi) __ is a template to create similar objects sharing common (a) A class
characteristics.
A class is a blueprint defining structure and behaviour. Objects are created from it.
vii) Which of the following is a keyword in Java? (c) break
'break' is a reserved keyword. 'Switch' (capital S), 'FOR' (must be lowercase), 'object' (not a keyword) are invalid.
viii) Which of the following is NOT a legal identifier in Java? (b) new
'new' is a reserved keyword and cannot be used as an identifier. _test, $amount, a_b are all legal.
ix) Which of the following is NOT a binary operator? (d) ! — Logical NOT is a unary operator
! operates on a single operand (unary). &&, >, and * all require two operands (binary).
x) [Link]("Six ="+3+3); gives: (c) Six =33
String + int = String concatenation. "Six ="+3 = "Six =3", then +3 = "Six =33". Left-to-right evaluation.
xi) Keyword used to include a class from another package? (c) import
'import' brings external classes/packages into the current source file.
xii) Symbol for single-line comment in Java? (c) //
// starts a single-line comment. /* */ is block comment. /** */ is Javadoc comment.
xiii) Value of [Link](44.6)? (b) 44.0
[Link]() returns the largest double value <= the argument. floor(44.6) = 44.0 (always returns double).
xiv) Value of [Link](-4.9)? (c) -4.0
[Link]() returns the smallest double >= argument. The smallest integer >= -4.9 is -4, so -4.0.
—1—
xv) A sequence of statements in curly brackets is called __. (a) a block
A block { } groups multiple statements together and defines a scope.
xvi) Which is mandatory in a switch statement? (d) case
At least one 'case' label is required. break, continue, and default are all optional.
xvii) Which loop executes at least once? (b) do while loop
In do-while, the body runs first, condition checked after. Guarantees minimum one execution.
xviii) Which is NOT a jump statement in Java? (c) void
'void' is a return type keyword, not a jump statement. return, break, continue are jump statements.
xix) Unsolicited emails and advertisements are collectively called (b) spam
__.
Spam = unsolicited bulk messages, typically advertisements sent without recipient's consent.
xx) __ is an attempt to exploit a computer system. (a) hacking
Hacking involves exploiting vulnerabilities to gain unauthorised access to computer systems.
Q2 Short Answer Questions [20 Marks]
i) Find output: [2 Marks]
int a=8, b=-3, c=4;
c+=++a / c++ * ++b*c++;
[Link](c);
Step-by-step evaluation:
→ Initial values: a=8, b=-3, c=4
→ ++a → a becomes 9 (pre-increment, value used = 9)
→ c++ → c used as 4 in expression, then c becomes 5
→ ++b → b becomes -2 (pre-increment, value used = -2)
→ c++ → c used as 5 in expression, then c becomes 6
→ Expression right side = 9/4 * (-2) * 5 = 2 * (-2) * 5 = -20 (integer division: 9÷4=2)
→ c += -20 → c = 6 + (-20) = -14
✔ Output: -14
ii) Write equivalent Java expression for (2x-1)/(x-4): [2 Marks]
(2*x - 1) / (x - 4)
Tip: Use (double)(2*x-1)/(x-4) if a decimal result is needed.
iii) Find output: [2 Marks]
int a=5, b=3, c;
c = a/b*a + a*b/a;
[Link](c);
→ a/b = 5/3 = 1 (integer division)
→ 1*a = 1*5 = 5
→ a*b = 5*3 = 15 → 15/a = 15/5 = 3
→c=5+3=8
✔ Output: 8
—2—
iv) Rewrite using switch statement: [2 Marks]
Original ternary:
int n=20;
double r = (n==20) ? n*2 : (n==30) ? n*30 : n*100;
Switch equivalent:
int n = 20;
double r;
switch(n) {
case 20: r = n * 2;
break;
case 30: r = n * 30;
break;
default: r = n * 100;
}
v) Find output (switch with a=1): [2 Marks]
int a=1;
switch(a) {
case 1: [Link]("A");
case 2: [Link]("B");
default: [Link]("C");
}
→ a=1 matches case 1. No break after case 1 → fall-through to case 2 and default.
→ All three print statements execute sequentially.
✔ Output: ABC
vi) Find output (Math functions): [2 Marks]
double y = [Link](-2.3) + [Link](-18.9);
[Link](y);
→ [Link](-2.3) = -2.0 (smallest integer >= -2.3 is -2)
→ [Link](-18.9) = -19.0 (largest integer <= -18.9 is -19)
→ y = -2.0 + (-19.0) = -21.0
✔ Output: -21.0
vii) Find output (while loop): [2 Marks]
int n, i=5;
while(i<=8) {
n=77;
[Link](i+" "+n);
n=n-1;
i++;
}
→ n is reset to 77 at the start of each iteration, so n-1 never persists.
→ Loop runs for i = 5, 6, 7, 8 (stops when i=9)
✔ Output: 5 77 | 6 77 | 7 77 | 8 77 (each on new line)
viii) Rewrite for loop using while loop: [2 Marks]
Original:
for(int i=100; i>=10; i--) {
[Link](i);
}
While equivalent:
—3—
int i = 100;
while(i >= 10) {
[Link](i);
i--;
}
ix) Find output (do-while): [2 Marks]
int c=1;
do {
[Link](c++);
} while(c<5);
[Link](c);
→ c=1: print 1, c→2. c<5? YES
→ c=2: print 2, c→3. c<5? YES
→ c=3: print 3, c→4. c<5? YES
→ c=4: print 4, c→5. c<5? NO — exit loop
→ After loop: [Link](c) = print 5
✔ Output: 12345
x) Output + count of 'continue' executions: [2 Marks]
int i;
for(i=1; i<=7; i++) {
if(i%2 == 1)
continue;
[Link](i+" ");
}
→ Odd values (i%2==1): i = 1, 3, 5, 7 → continue executes, print is skipped
→ Even values: i = 2, 4, 6 → printed
✔ Output: 2 4 6 | 'continue' executes 4 times (i = 1, 3, 5, 7)
SECTION B — PROGRAMMING QUESTIONS Answer Any 4
Q3a Palindrome Number [10 Marks]
A number is palindrome if it equals its reverse. E.g. 242, 151, 1001.
import [Link];
class Palindrome {
public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
[Link]("Enter a number: ");
int num = [Link]();
int original = num; // save original
int rev = 0;
// Reverse the number digit by digit
while (num > 0) {
int digit = num % 10; // extract last digit
rev = rev * 10 + digit; // append to reversed number
num = num / 10; // remove last digit
}
if (original == rev)
—4—
[Link](original + " is a Palindrome number.");
else
[Link](original + " is NOT a Palindrome number.");
}
}
Q3b Series: 3, 33, 333, 3333... [5 Marks]
Each term = previous term * 10 + 3. Pattern builds naturally in a loop.
import [Link];
class Series3 {
public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
[Link]("Enter number of terms (n): ");
int n = [Link]();
int term = 0;
for (int i = 1; i <= n; i++) {
term = term * 10 + 3; // builds: 3, 33, 333, 3333 ...
[Link](term);
if (i < n) [Link](", ");
}
[Link]();
}
}
Q4 Triangle / Inverted Triangle Patterns (switch) [15 Marks]
Pattern 1 (choice=1) Pattern 2 (choice=2)
1 55555
22 4444
333 333
4444 22
55555 1
import [Link];
class TrianglePattern {
public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
[Link]("Enter choice (1=Triangle, 2=Inverted Triangle): ");
int choice = [Link]();
if (choice == 1) {
// Pattern 1: row i prints digit i, exactly i times
for (int i = 1; i <= 5; i++) {
for (int j = 1; j <= i; j++)
[Link](i);
[Link]();
}
}
else if (choice == 2) {
// Pattern 2: row i prints digit (6-i), (6-i) times
for (int i = 1; i <= 5; i++) {
int d = 6 - i;
for (int j = 1; j <= d; j++)
[Link](d);
—5—
[Link]();
}
}
else {
[Link]("INVALID CHOICE");
}
}
}
Q5a Greatest and Smallest among N Numbers [8 Marks]
import [Link];
class MinMax {
public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
[Link]("How many numbers? ");
int n = [Link]();
[Link]("Enter number 1: ");
int num = [Link]();
int greatest = num; // initialise with first input
int smallest = num;
for (int i = 2; i <= n; i++) {
[Link]("Enter number " + i + ": ");
num = [Link]();
if (num > greatest) greatest = num;
if (num < smallest) smallest = num;
}
[Link]("Greatest number: " + greatest);
[Link]("Smallest number: " + smallest);
}
}
Q5b Sum of Series: 1, (1+2), (1+2+3)... [7 Marks]
Each term T(k) = 1+2+...+k. We accumulate each term, then add to total.
import [Link];
class SeriesSum {
public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
[Link]("Enter n: ");
int n = [Link]();
long totalSum = 0;
long termSum = 0;
for (int k = 1; k <= n; k++) {
termSum += k; // term grows: 1, 3, 6, 10 ...
totalSum += termSum; // add current term to grand total
}
[Link]("Sum of first " + n + " terms = " + totalSum);
}
}
Q6a All Three-Digit Prime Numbers [10 Marks]
Check each number from 100 to 999. A prime has no factors other than 1 and itself.
—6—
class ThreeDigitPrimes {
public static void main(String[] args) {
[Link]("Three-digit prime numbers:");
int count = 0;
for (int num = 100; num <= 999; num++) {
boolean isPrime = true;
// Only check divisors up to sqrt(num) — optimisation
for (int i = 2; i <= [Link](num); i++) {
if (num % i == 0) {
isPrime = false;
break;
}
}
if (isPrime) {
[Link]("%4d", num);
count++;
if (count % 10 == 0) [Link](); // 10 per row
}
}
[Link]("\nTotal three-digit primes: " + count);
}
}
Q6b Niven Number [5 Marks]
A number with >= 2 digits, divisible by its digit sum. Example: 18 → 1+8=9, 18%9=0.
import [Link];
class NivenNumber {
public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
[Link]("Enter a number: ");
int num = [Link]();
if (num < 10) {
[Link](num + " must have at least 2 digits.");
} else {
int temp = num, digitSum = 0;
while (temp > 0) {
digitSum += temp % 10; // extract and add each digit
temp /= 10;
}
if (num % digitSum == 0)
[Link](num + " IS a Niven number. (Digit sum = " + digitSum + ")");
else
[Link](num + " is NOT a Niven number. (Digit sum = " + digitSum + ")");
}
}
}
Q7a Factorials of All Numbers Between m and n [10 Marks]
Conditions: m>0, n>0, m<n. Compute n! = 1 x 2 x 3 x ... x n for each number.
import [Link];
class FactorialRange {
public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
—7—
[Link]("Enter m (lower bound): ");
int m = [Link]();
[Link]("Enter n (upper bound): ");
int n = [Link]();
if (m <= 0 || n <= 0 || m >= n) {
[Link]("Invalid input. Ensure m>0, n>0 and m<n.");
} else {
for (int num = m; num <= n; num++) {
long fact = 1;
for (int i = 1; i <= num; i++) {
fact *= i; // multiply: 1*2*3*...*num
}
[Link](num + "! = " + fact);
}
}
}
}
Q7b Temperature Converter (switch-case) [5 Marks]
Formulae: C = 5/9 x (F - 32) | F = 1.8 x C + 32
import [Link];
class TempConverter {
public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
[Link]("1. Fahrenheit to Celsius");
[Link]("2. Celsius to Fahrenheit");
[Link]("Enter your choice: ");
int choice = [Link]();
switch(choice) {
case 1:
[Link]("Enter temperature in Fahrenheit: ");
double f = [Link]();
double c = 5.0/9.0 * (f - 32);
[Link]("Result: %.2f Celsius%n", c);
break;
case 2:
[Link]("Enter temperature in Celsius: ");
double cel = [Link]();
double fahr = 1.8 * cel + 32;
[Link]("Result: %.2f Fahrenheit%n", fahr);
break;
default:
[Link]("ERROR: Invalid choice. Enter 1 or 2.");
}
}
}
Q8a Multiplication Table (10 to 20, up to 10 rows) [8 Marks]
class MultiplicationTable {
public static void main(String[] args) {
for (int num = 10; num <= 20; num++) {
[Link]("--- Table of " + num + " ---");
for (int i = 1; i <= 10; i++) {
[Link]("%2d x %2d = %3d%n", num, i, num*i);
}
—8—
[Link]();
}
}
}
Q8b Income Tax Calculator [7 Marks]
Income Range (Rs.) Tax Rate
0 – 2,50,000 0% (No Tax)
2,50,001 – 5,00,000 5%
5,00,001 – 10,00,000 20%
Above 10,00,000 30%
import [Link];
class IncomeTax {
public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
[Link]("Enter your annual income: ");
long income = [Link]();
double tax = 0;
String rate = "";
if (income <= 250000) {
tax = 0;
rate = "0% (No Tax)";
}
else if (income <= 500000) {
// Tax only on amount above 2,50,000
tax = (income - 250000) * 5.0 / 100;
rate = "5%";
}
else if (income <= 1000000) {
// 5% on 2.5L slab + 20% on remainder
tax = 250000 * 5.0 / 100
+ (income - 500000) * 20.0 / 100;
rate = "20%";
}
else {
// 5% on 2.5L + 20% on 5L + 30% on remainder
tax = 250000 * 5.0 / 100
+ 500000 * 20.0 / 100
+ (income - 1000000) * 30.0 / 100;
rate = "30%";
}
[Link]("Income : Rs." + income);
[Link]("Applicable Tax Rate : " + rate);
[Link]("Tax Payable : Rs." + (long)tax);
}
}
— END OF SOLUTIONS —
St. Joseph's School, Bhagalpur · Computer Applications Class IX · 2025–26
—9—