Class 9 Practice Questions 05012025
Class 9 Practice Questions 05012025
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.
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);
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);
}
}