0% found this document useful (0 votes)
1 views4 pages

? Java Programming Practice Questions

The document contains a comprehensive list of 70 Java programming practice questions covering various topics including basics, operators, methods, arrays, strings, OOP, inheritance, recursion, and advanced logic. Each section includes specific tasks such as declaring variables, implementing loops, creating classes, and solving logical challenges. It also provides tips for focusing on key areas that are commonly tested in exams.

Uploaded by

duaarshad2006
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)
1 views4 pages

? Java Programming Practice Questions

The document contains a comprehensive list of 70 Java programming practice questions covering various topics including basics, operators, methods, arrays, strings, OOP, inheritance, recursion, and advanced logic. Each section includes specific tasks such as declaring variables, implementing loops, creating classes, and solving logical challenges. It also provides tips for focusing on key areas that are commonly tested in exams.

Uploaded by

duaarshad2006
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/ 4

Java Programming Practice Questions

Basics & Variables

1. Declare variables of all primitive types in Java and print their values.

2. Write a program to swap two numbers without using a third variable.

3. Write a program to find the largest of 3 numbers using if-else.

4. Write a program to check if a number is positive, negative, or zero.

5. Write a program to print the ASCII value of a character.

6. Write a program to calculate simple interest for given principal, rate, and time.

7. Write a program to convert Celsius to Fahrenheit and vice versa.

Operators & Loops

8. Write a program to print numbers from 1 to 50 using a while loop.

9. Write a program to print the sum of all even numbers between 1 and 100.

10. Write a program to calculate the factorial of a number using a for loop.

11. Print the multiplication table of a number entered by the user.

12. Find the sum of digits of a given number.

13. Write a program to reverse a number (e.g., 123 → 321).

14. Write a program to check if a number is Armstrong.

15. Print all prime numbers between 1 and 100.

Methods / Functions

16. Write a method isEven(int n) to check if a number is even.

17. Write a method sum(int a, int b) to return the sum of two numbers.

18. Write a method maxOfThree(int a, int b, int c) to find the largest number.

19. Write a method to calculate the factorial of a number using recursion.


20. Write a method to check if a string is a palindrome.

21. Write a method reverseString(String s) to reverse a string.

22. Write a method to find the nth Fibonacci number using recursion.

23. Write a method to find GCD of two numbers.

24. Explain method overloading and give an example.

25. Explain method overriding with a simple example using inheritance.

Arrays

26. Declare an array of size n and read values from the user.

27. Find the sum of all elements in an array.

28. Find the largest and smallest element in an array.

29. Count the number of even and odd numbers in an array.

30. Find duplicates in an array.

31. Reverse an array without using a second array.

32. Sort an array in ascending and descending order.

33. Merge two arrays into a third array.

34. Remove duplicate elements from an array.

35. Write a program to shift all zeros in an array to the end.

Strings

36. Count the number of words in a sentence using split().

37. Reverse a string using a loop.

38. Check if a string is a palindrome.

39. Convert a string to uppercase, lowercase, and capitalize the first letter of each word.

40. Count the number of vowels and consonants in a string.

41. Count the frequency of each character in a string.


42. Remove all spaces from a string.

43. Replace all vowels in a string with *.

44. Compare two strings without using .equals().

OOP (Classes & Objects)

45. Create a Person class with name, age, and address. Add getters and setters.

46. Add a method displayInfo() in the Person class to print all attributes.

47. Create a BankAccount class with deposit, withdraw, and checkBalance methods.

48. Create a Car class with attributes brand, model, year. Add a method to calculate car age.

49. Implement constructor overloading in a class.

50. Explain the difference between instance variables and local variables.

51. Explain encapsulation and implement it in a class.

52. Create a Student class with an array of marks and a method to calculate total and
average.

Inheritance & Polymorphism

53. Create a base class Animal and derived classes Dog and Cat. Implement a method
sound().

54. Demonstrate method overriding in the above example.

55. Create a class hierarchy for Shape → Rectangle / Circle / Triangle and calculate area.

56. Demonstrate polymorphism by calling overridden methods using a base class reference.

Recursion / Logical Challenges

57. Fibonacci series using recursion.

58. Factorial using recursion.

59. Find GCD using recursion.


60. Reverse a string using recursion.

61. Print numbers from n to 1 using recursion.

62. Sum of digits of a number using recursion.

Misc / Advanced Logic

63. Menu-driven program for a Student class to add, view, and exit.

64. Implement a simple calculator class with addition, subtraction, multiplication, division.

65. Program to check if a number is perfect.

66. Program to check if a number is a strong number.

67. Program to find all pairs in an array whose sum is a given number.

68. Program to count frequency of each number in an array.

69. Program to find the second largest number in an array.

70. Program to check if two strings are anagrams.

Pro Tip:

• Focus on arrays, methods, OOP, and strings—most teachers love mixing these.

• Many exam questions are small variations of these 70 questions.

You might also like