Unit 1 - Java Programming Practice Questions
Section A: Variables, Data Types, and Operators
1. Write a program to swap two numbers without using a third variable.
2. Write a program to calculate the area and perimeter of a rectangle.
3. Write a program to convert temperature from Celsius to Fahrenheit and vice versa.
4. Write a program to check whether a number is even or odd using a conditional operator.
5. Write a program to demonstrate typecasting between int, float, and double.
6. Write a program to find the greatest of three numbers using if-else.
7. Write a program to display ASCII values of all lowercase letters.
8. Write a program to evaluate an expression like a + b * c - d / e and explain precedence.
Section B: Flow Control Statements
9. Write a program to check if a year is a leap year or not.
10. Write a program to find whether a number is prime or not.
11. Write a program to print the multiplication table of any number using for loop.
12. Write a program to find the sum of digits of a given number using a while loop.
13. Write a program to check if a character is a vowel or consonant using switch statement.
14. Write a program to print Fibonacci series up to n terms using loops.
15. Write a program to display all numbers from 1 to 100 divisible by 3 and 5.
Section C: Basic OOP Concepts
16. Create a class Student with attributes name, rollNo, and marks and print the details.
17. Write a program to demonstrate the use of this keyword.
18. Create a class Calculator with overloaded methods add(int, int), add(double, double), and
add(int, int, int).
19. Write a program using a class to find the factorial of a number using recursion.
20. Create a class BankAccount that allows deposit, withdraw, and balance display using
methods.