This collection of 50 Java coding questions is designed to help you master the basics and build strong problem-solving skills. Whether you’re preparing for a Java interview, studying for an exam, or simply practicing your logic, this guide is a great companion.
Each question comes with:
A clear problem statement
Humanized logic explanation
Java code
Output example
🔹 21. Find Duplicate Elements in Array
🔹 22. Count Occurrence of Each Character
🔹 23. Print Star Pyramid
🔹 24. Check Leap Year
🔹 25. GCD of Two Numbers
🔹 26. LCM of Two Numbers
🔹 27. Check Anagram Strings
🔹 28. Convert String to Integer
🔹 29. Convert Integer to String
🔹 30. Remove White Spaces
🔹 31. Count Words in String
🔹 32. Find Second Largest in Array
🔹 33. Sum of Digits in Number
🔹 34. Generate Random Number
🔹 35. Swap Without 3rd Variable
🔹 36. Simple Calculator
🔹 37. Reverse Linked List (Concept)
🔹 38. Check Armstrong for n-digits
🔹 39. Remove Duplicates from String
🔹 40. Java Class Example (OOP)
🔹 41. Abstract Class
🔹 42. Interface Example
🔹 43. StringBuilder Reverse
🔹 44. Check if Number is Perfect
🔹 45. Print ASCII Values
🔹 46. Sort Array in Descending
🔹 47. Convert Char to Int and Vice Versa
🔹 48. Find Missing Number (1 to n)
🔹 49. Check String Rotation
🔹 50. Find Frequency of Elements in Array
Respective output for questions 21 to 50:
| 🔢 Q.No | Question Name | Output (Example) |
|---|---|---|
| 21 | Find Duplicate Elements in Array | Duplicate: 2, 1 |
| 22 | Count Occurrence of Each Character | {p=1, r=2, o=1, g=2, a=1, m=2, i=1, n=1} |
| 23 | Print Star Pyramid | <br><br> **** ***** |
| 24 | Check Leap Year | Leap Year |
| 25 | GCD of Two Numbers | GCD: 6 |
| 26 | LCM of Two Numbers | LCM: 60 |
| 27 | Check Anagram Strings | Anagram |
| 28 | Convert String to Integer | 123 |
| 29 | Convert Integer to String | 456 |
| 30 | Remove White Spaces | HelloWorldJava |
| 31 | Count Words in String | Words: 3 |
| 32 | Find Second Largest in Array | Second Largest: 20 |
| 33 | Sum of Digits in Number | Sum: 10 |
| 34 | Generate Random Number | Random: 42 (varies each time) |
| 35 | Swap Without 3rd Variable | a = 10, b = 5 |
| 36 | Simple Calculator | 15 (for op = '+') |
| 37 | Reverse Linked List | New head node reference (logic only, no print) |
| 38 | Check Armstrong for n-digits | Armstrong |
| 39 | Remove Duplicates from String | progamin |
| 40 | Java Class Example (OOP) | BMW runs at 200km/h |
| 41 | Abstract Class | Bark |
| 42 | Interface Example | Flying... |
| 43 | StringBuilder Reverse | olleh |
| 44 | Check if Number is Perfect | Perfect |
| 45 | Print ASCII Values | A: 65 ... Z: 90 |
| 46 | Sort Array in Descending | [8, 5, 3, 1] |
| 47 | Convert Char to Int and Vice Versa | ASCII: 65, Back: A |
| 48 | Find Missing Number (1 to n) | Missing: 3 |
| 49 | Check String Rotation | Rotation |
| 50 | Find Frequency of Elements in Array |
