Java Exercises

Here are some Java exercises to help you hone your skills as a programmer!

  1. Print an Integer in Java
  2. Add Two Integers in Java
  3. Multiply Two Floating-Point Numbers in Java
  4. Calculate Quotient and Remainder in Java
  5. Find ASCII of a Character in Java
  6. Check If a Number is Even or Odd in Java
  7. Check If a Letter is A Vowel or A Consonant in Java
  8. Find Roots Of A Quadratic Equation in Java
  9. Swap Two Numbers in Java
  10. Find the Largest Among Four Numbers in Java
  11. Check For Leap Year in Java
  12. Check Whether a Number is Positive or Negative in Java
  13. Calculate The Sum Up To 100 in Java
  14. Compute Factorial in Java
  15. Check If a Character is An Alphabet Character or Not in Java
  16. Compute Multiplication Table in Java
  17. Display Factors of a Number in Java
  18. Check Whether a Number can be Expressed as Sum of Two Prime Numbers in Java
  19. Sum Natural Numbers using Recursion in Java
  20. Display Prime Numbers Between Two Intervals in Java
  21. Program to Check Armstrong Number in Java
  22. Display Armstrong Number Using Loops in Java
  23. Display Armstrong Number Between Two Intervals in Java
  24. Function to Display Prime Numbers Between Intervals in Java
  25. Display Fibonacci Series in Java
  26. Convert Int Type Variables to Long in Java
  27. Convert Double Variable to Integer in Java
  28. Convert String Variable to Double in Java
  29. Convert Double Variable to String in Java
  30. Print Floyd’s Triangle in java
  31. Display the Alphabet A to Z in Java
  32. Count Digits of an Integer in Java
  33. Calculate the Power of a Number in Java
  34. Make a Simple Calculator in Java
  35. Calculate Average Using Arrays in Java
  36. Calculate the Power of a Number Using Recursion in Java
  37. Convert Primitive Type to Object in Java
  38. Implement Bubble Sort Algorithm in Java
  39. Add Two Dates in Java
  40. Join Two Lists in Java
  41. Convert an Array to ArrayList in Java
  42. Get Current Working Directory in Java
  43. Convert Map (HashMap) to List in Java
  44. Convert Array to Set (HashSet) in Java
  45. Implement Merge Sort Algorithm in Java
  46. Implement Quick Sort Algorithm in Java
  47. Compute Lowest Common Multiple (LCM) of Two Numbers in Java
  48. Check Whether a Number is Palindrome or Not in Java
  49. Check Whether a Number is Prime or Not in Java
  50. Find Factorial of a Number Using Recursion in Java
  51. Find Greatest Common Denominator (GCD) in Java
  52. Convert Binary Number to Decimal in Java
  53. Convert Decimal to Octal Number in Java
  54. Reverse a Sentence in Java
  55. Convert Decimal to Binary Number in Java
  56. Convert Octal Number to Decimal in Java
  57. Convert Octal to Binary in Java
  58. Convert Binary to Octal in Java
  59. Find Largest Element of an Array in Java
  60. Calculate Standard Deviation in Java
  61. Matrix Addition using Arrays in Java
  62. Matrix Multiplication Using Arrays in Java
  63. Matrix Multiplication by User-Defined Function in Java
  64. Transpose a Matrix in Java
  65. Find the Frequency of a Character in a String in Java
  66. Count the Number of Vowels and Consonants in a Sentence in Java
  67. Sort Words Alphabetically in Java
  68. Add Two Complex Numbers in Java
  69. Calculate Difference between Two Time Periods in Java
  70. Create a Half Pyramid Pattern in Java
  71. Remove All White Spaces from a String in Java
  72. Print an Array in Java
  73. Convert String to Date in Java
  74. Round a Number to n Decimal Places in Java
  75. Concatenate Two Arrays in Java
  76. Convert Character to String and Vice-Versa in Java
  77. Check for a Value in an Array in Java
  78. Check if a String is Empty or Null in Java
  79. Get Current Date and Time in Java
  80. Convert Milliseconds to Minutes and Seconds in Java
  81. Reverse a Number in Java
  82. Convert ArrayList to an Array in Java
  83. Convert Set to Array in Java
  84. Convert Byte Array to Hexadecimal in Java
  85. Create String from Contents of a File in Java
  86. Append Text to an Existing File in Java
  87. Convert a Stack Trace to a String in Java
  88. Convert File to Byte Array in Java
  89. Convert Byte[] to File in Java
  90. Convert Input Stream to String in Java
  91. Convert Output Stream to String in Java
  92. Lookup Enum by String value in Java
  93. Compare Two Strings in Java
  94. Check if a String is Numeric in Java
  95. Create Directories in Java
  96. Rename a File in Java
  97. Get all Files Present in a Directory in Java
  98. Program to Copy Files in Java
  99. Convert Char Type Variable to Int in Java
  100. Convert Int Type Variables to Char in Java
  101. Convert Int Type Variables to Long in Java
  102. Convert Boolean Variables into String in Java
  103. Convert String Type Variables to Boolean in Java
  104. Convert String Type Variables into Int in Java
  105. Convert Int Type Variables to String in Java
  106. Call One Constructor from another in Java
  107. Calculate the Execution Time of Method in Java
  108. Convert the InputStream into Byte Array in Java
  109. Convert a String into the InputStream in Java
  110. Iterate through Each Character of the String in Java
  111. Capitalize the First Character of Each Word in a String in Java
  112. Clear the String Buffer in Java
  113. Generate Random Strings in Java
  114. Compute All the Permutations of the String in Java
  115. Check if Two Strings are Anagram in Java
  116. Create an Immutable Class in Java
  117. Create Custom Exception in Java
  118. Print Object of a Class in Java
  119. Create File and Write to the File in Java
  120. Read the Content of a File Line by Line in Java
  121. Delete File in Java
  122. Delete a Directory in Java
  123. Get File Extension in Java
  124. Get Name of a File from Absolute Path in Java
  125. Get Relative Path from Two Absolute Paths in Java
  126. Count Number of Lines Present in the File in Java
  127. Determine the Class of an Object in Java
  128. Convert Object to Primitive Type in Java
  129. Implement Binary Search Algorithm in Java
  130. Implement Private Constructor in Java
  131. Pass Lambda Expression as Method Argument in Java
  132. Pass Method as Argument to Other Method in Java
  133. Convert a String into InputStream in Java
  134. Call Super-class Constructor from Child Class Constructor in Java
  135. Differentiate String == Operator and Equals() Method in Java
  136. Implement Switch Statement on Strings in Java
  137. Calculate Compound Interest in Java
  138. Calculate Simple Interest in Java
  139. Implement Multiple Inheritance in Java
  140. Determine Name and Version of the Operating System in Java
  141. Check If Two of Three Boolean Variables are True in Java
  142. Iterate over Enum in Java
  143. Check the Birthday and Print Birthday Message in Java
  144. Implement LinkedList in Java
  145. Implement Stack Data Structure in Java
  146. Get the Middle Element of LinkedList in a Single Iteration in Java
  147. Implement the Queue Data Structure in Java
  148. Convert the LinkedList into an Array in Java
  149. Convert an Array to LinkedList in Java
  150. Convert a String into an ArrayList in Java
  151. Convert a String into an ArrayList in Java
  152. Iterate over an ArrayList in Java
  153. Access Elements From a LinkedList in Java
  154. Add Elements to a LinkedList in Java
  155. Remove Elements from the LinkedList in Java
  156. Implement the Graph Data Structure in Java
  157. Check If a String is a Valid Shuffle of Two Distinct Strings in Java

%d bloggers like this: