Looking for Java exercises to test your Java skills, then explore our topic-wise Java practice exercises? Here you will get 25 plus practice problems that help to upscale your Java skills.
As we know Java is one of the most popular languages because of its robust and secure nature. But, programmers often find it difficult to find a platform for Java Practice Online. In this article, we have provided Java Practice Programs. That covers various Java Core Topics that can help users with Java Practice.
So, with ado further take a look at our free Java Exercises to practice and develop your Java programming skills. Our Java programming exercises Practice Questions from all the major topics like loops, object-oriented programming, exception handling, and many more.
Java Practice ProgramsThis Java exercise is designed to deepen your understanding and refine your Java coding skills, these programs offer hands-on experience in solving real-world problems, reinforcing key concepts, and mastering Java programming fundamentals. Whether you're a beginner who looking to build a solid foundation or a professional developer aiming to sharpen your expertise, our Java practice programs provide an invaluable opportunity to sharpen your craft and excel in Java programming language .
1. Write Hello World Program in JavaJava enthusiasts can also benefit from practicing various java exercises on the GeeksforGeeks Online Practice Platform, where challenges cater to both beginners and advanced programmers.
The solution to the Problem is mentioned below:
Java
// Java Program to Print
// Hello World
import java.io.*;
// Driver Class
class GFG {
// main function
public static void main(String[] args)
{
// Printing Hello World
System.out.println("Hello World!");
}
}
2. Write a Program in Java to Add two Numbers.
Input: 2 3Click Here for the Solution 3. Write a Program to Swap Two Numbers
Output: 5
Input: a=2 b=5Click Here for the Solution 4. Write a Java Program to convert Integer numbers and Binary numbers.
Output: a=5 b=2
Input: 9Click Here for the Solution 5. Write a Program to Find Factorial of a Number in Java.
Output: 1001
Input: 5Click Here for the Solution 6. Write a Java Program to Add two Complex Numbers.
Output: 120
Input: 1+2iClick Here for the Solution 7. Write a Program to Calculate Simple Interest in Java
4+5i
Output: 5+7i
Input : P = 10000 R = 5 T = 5Click Here for the Solution 8. Write a Program to Print the Pascal's Triangle in Java
Output : 2500
Input : N = 5Click Here for the Solution 9. Write a Program to Find Sum of Fibonacci Series Number
Output:
1
1 1
1 2 1
1 3 3 1
1 4 6 4 1
1 5 10 10 5 1
Input: n = 4Click Here for the Solution Java Exercise on Pattern 10. Write a Program to Print Pyramid Number Pattern in Java.
Output: 33
Explaination: Sum of numbers at even indexes = 0 + 1 + 3 + 8 + 21 = 33.
*Click Here for the Solution 11. Write a Java Program to Print Pattern.
***
*****
*******
* * * * * *Click Here for the Solution 12. Write a Java Program to Print Pattern.
* *
* *
* *
* *
* * * * * *
1Click Here for the Solution 13. Java Program to Print Patterns.
2 1 2
3 2 1 2 3
4 3 2 1 2 3 4
5 4 3 2 1 2 3 4 5
6 5 4 3 2 1 2 3 4 5 6
*Click Here for the Solution Array Exercises in Java 14. Write a Java Program to Compute the Sum of Array Elements.
***
*****
*******
*********
***********
*********
*******
*****
***
*
Input: [ 2, 4, 6, 7, 9]Click Here for the Solution 15. Write a Java Program to Find the Largest Element in Array
Output: 28
Input: [ 7, 2, 5, 1, 4]Click Here for the Solution 16. Write Java Program to Find the Tranpose of Matrix
Output: 7
Input:Click Here for the Solution 17. Java Array Program For Array Rotation
[ [ 1, 2, 3 ]
[ 4, 5, 6 ]
[ 7, 8, 9 ] ]
Output:
[ [ 1, 4, 7]
[ 2, 5, 8]
[ 3, 6, 9] ]
Input: arr[] = {1, 2, 3, 4, 5, 6, 7}, d = 2Click Here for the Solution 18. Java Array Program to Remove Duplicate Elements From an Array
Output: 3 4 5 6 7 1 2Explaination: d=2 so 2 elements are rotated to the end of the array. So, 1 2 is rotated back
So, Final result: 3, 4, 5, 6, 7, 1, 2
Input: [ 1, 2, 2, 3, 3, 3, 4, 5 ]Click Here for the Solution 19. Java Array Program to Remove All Occurrences of an Element in an Array
Output: [ 1, 2, 3, 4, 5 ]
Input: array = [ 1, 2, 1, 3, 5, 1 ] , key = 1Click Here for the Solution String Exercises in Java 20. Java program to check whether a string is a Palindrome
Output: [2, 3, 5]Explaination: all the occurrences of element 1 is removed from the array So, array becomes from
[ 1, 2, 1, 3, 5, 1 ] to
Final result: [2, 3, 5]
Input: "racecar"Click Here for the Solution 21. Java String Program to Check Anagram
Output: YesExplaination: As racerar after reversing becomes racecar. As Reverse of String is same as String so it is Palindrome
Input: str1 = "Silent"Click Here for the Solution 22. Java String Program to Reverse a String
str2 ="Listen"
Output: Strings are AnagramExplaination: As all the elements in str1 are exact same as to create str2 .
i.e., we can create str2 using elements of str1 without removing any element or removing any extra element.
Input: str= "Geeks"Click Here for the Solution 23. Java String Program to Remove leading zeros
Output: "skeeG"
Input : 00000123569Click Here for the Solution Java Practice Problems for Searching Algorithms 24. Write a Java Program for Linear Search.
Output : 123569
Click Here for the Solution 25. Write a Binary Search Program in Java.Time Complexity: O(N)
Space Complexity: O(N)
Click Here for the Solution Practice Problems in Java Sorting Algorithms 26. Java Program for Bubble Sort.Time Complexity: O(logN)
Space Complexity: O(N)
Click Here for the Solution 27. Write a Program for Insertion Sort in Java.Time Complexity: O(N 2 )
Space Complexity: O(1)
Click Here for the Solution 28. Java Program for Selection Sort.Time Complexity: O(N 2 )
Space Complexity: O(1)
Click Here for the Solution 29. Java Program for Merge Sort.Time Complexity: O(N 2 )
Space Complexity: O(1)
Click Here for the Solution 30. Java Program for QuickSort.Time Complexity: O(N logN)
Space Complexity: O(N)
Click Here for the Solution ConclusionTime Complexity: O(N logN)
Space Complexity: O(1)
After completing these Java exercises you are a step closer to becoming an advanced Java programmer. We hope these exercises have helped you understand Java better and you can solve beginner to advanced-level questions on Java programming.
Solving these Java programming exercise questions will not only help you master theory concepts but also grasp their practical applications, which is very useful in job interviews.
More Java Practice ExercisesClick Here - To Practice Java Online please check our Practice Portal.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4