0% found this document useful (0 votes)
48 views3 pages

Class 9 Practice Questions 05012025

Uploaded by

mdnizaaaaam
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)
48 views3 pages

Class 9 Practice Questions 05012025

Uploaded by

mdnizaaaaam
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/ 3

Class 9

Computer Mock Test


Date: 05.01.2025 Time: ____
Name: _____________
Marks Obtained: _____________
Remarks: _____________

Variables and Data Types


i. Write a program to accept the radius of a circle as a double and calculate its area and circumference. Ensure the
output is rounded to two decimal places.
ii. Write a program to swap two numbers without using a third variable.

2. Loops (for, while, do-while)


i. Write a program to check whether a given number is a palindrome or not using a while loop.
ii. Write a program to calculate the factorial of a number using a for loop.
iii. Write a program to generate and display the Fibonacci series up to n terms using a do-while loop.

3. Switch Statements
i. Write a program to display the number of days in a month based on the month number (1 for January, 2 for
February, etc.). Use a switch statement. Consider leap years for February.
ii. Write a menu-driven program using a switch statement to perform the following operations:
Check if a number is prime.
Check if a number is even or odd.
Exit the program.

4. If-Else If-Else Constructs


i. Write a program to classify a given year as a leap year or not.
ii. Write a program to calculate the grade of a student based on the following criteria:
Marks >= 90: Grade A
Marks >= 75 and < 90: Grade B
Marks >= 50 and < 75: Grade C
Marks < 50: Grade D
iii. Write a program to check if three given sides form a valid triangle. If valid, determine whether it is an
equilateral, isosceles, or scalene triangle.

5. Loop Conversions
i. Convert the following for loop into a while loop:
for (int i = 10; i >= 1; i--) {
System.out.println(i);
}
ii. Convert the following while loop into a for loop:
int i = 1, sum = 0;
while (i <= 10) {
sum += i;
i++;
}
System.out.println("Sum: " + sum);

6. Operators and Ternary Operators


i. Write a program to find the largest of three numbers using a ternary operator.
ii. Write a program to check whether a number is divisible by both 3 and 5, divisible by only one of them, or
divisible by neither. Use nested ternary operators.

7. Patterns
i. Write a program to print the following pattern:
*
**
***
****
ii. Write a program to print the following pattern:
1
12
123
1234
12345
iii. Write a program to print the following inverted pattern:
12345
1234
123
12
1

8. Debugging
i. Find and correct the errors in the following program:
public class Debug {
public static void main(String args[]) {
int a = 5, b = 10;
System.out.println("Product: " + a * b);
}
}
ii. Debug the following program to correctly display the sum of even numbers between 1 and 50:
public class Debug {
public static void main(String[] args) {
int sum = 0;
for (int i = 1; i <= 50; i++) {
if (i % 2 == 0);
sum += i;
}
System.out.println("Sum of even numbers: " + sum);
}
}

9. Find the Output


i. Predict the output of the following code:
public class Output {
public static void main(String[] args) {
int a = 10, b = 20;
System.out.println(a++ + --b);
System.out.println(a + b);
}
}
ii. Predict the output of the following code:
public class Output {
public static void main(String[] args) {
int x = 5;
for (int i = 1; i <= 3; i++) {
x += i;
System.out.println(x);
}
}
}

10. Theory Questions


i. Explain the difference between for, while, and do-while loops with examples.
ii. What are the advantages of using a switch statement over if-else?
iii. Write the syntax of a ternary operator and explain its use with an example.
iv. Explain the concept of "nested loops" and give an example where they are used.
v. What is the difference between break and continue statements in loops?

You might also like