Java Programming Practice Questions
Beginner Level
1. Input and Output
- Write a program to take two integers as input and print their sum.
2. Conditionals
- Check if a number is even or odd.
- Write a program to find the largest of three numbers.
3. Loops
- Print numbers from 1 to 10 using a for loop.
- Print the sum of the first n natural numbers.
- Print the multiplication table of a given number.
4. Arrays
- Take an array as input and print its elements.
- Find the maximum and minimum element in an array.
5. Basic String Operations
- Write a program to count vowels in a given string.
- Reverse a string.
Intermediate Level
6. Loops and Patterns
- Print the following pattern:
**
***
****
- Print the Fibonacci series up to n terms.
- Check if a number is prime or not.
7. Recursion
- Write a recursive program to calculate the factorial of a number.
- Write a program to find the GCD of two numbers using recursion.
8. 2D Arrays
- Print a 2D matrix.
- Find the sum of each row in a matrix.
9. OOP Basics
- Create a Car class with attributes name, color, and a method to display details.
- Write a program to demonstrate constructor overloading.
10. Method Overloading and Overriding
- Write a program to demonstrate method overloading.
- Create a parent class and override a method in its child class.
Advanced Level
11. Searching and Sorting
- Write a program to implement:
a. Linear Search
b. Binary Search
c. Bubble Sort
12. Exception Handling
- Handle ArithmeticException when dividing a number by zero.
13. Collections Framework
- Use an ArrayList to store integers and display them.
- Write a program to count the frequency of words in a sentence using HashMap.
14. File Handling
- Write a program to create a file and write some text into it.
- Read data from a file and display it.
15. Multithreading
- Create a program with two threads that print numbers from 1 to 5.
16. Palindrome Check
- Check if a given string or number is a palindrome.
17. Advanced Recursion
- Solve the Tower of Hanoi problem for n disks.
18. Matrix Problems
- Write a program to multiply two matrices.