6/4/26, 11:59 AM Java Exercises - Basic to Advanced Java Practice Programs with Solutions - GeeksforGeeks
Search... Courses Tutorials Practice Jobs S
Java Tutorial Advanced Java Interview Questions Exercises Examples Quizzes Projects Cheatsheet DSA in Java Java Collection
Share Your Experiences
Basics Java Exercises - Basic to Advanced Java Fresher Jobs Experienced Jobs
OOP & Interfaces Practice Programs with Solutions Python Developer
Last Updated : 24 Apr, 2026 Keylogic Infotech Private Limited
Collections Upto 1 Years • Onsite - Surat (Gujarat)
Apply by Sun Jun 07 2026
This Java exercise collection is designed to deepen your
Exception Handling
understanding of Java and refine your coding skills. The Application Support…
Java Advanced programs provide hands-on experience in solving real- Aress Software
Fresher • Onsite - Nashik (Maharashtra)
world problems, reinforce key concepts, and help you Apply by Sun Jun 07 2026
Practice Java
master Java fundamentals, including variables, control
iOS Engineer
Courses statements, arrays, strings, methods, and object-oriented Keylogic Infotech Private Limited
programming. Upto 2 Years • Onsite - Surat (Gujarat)
Summer SkillUp Explore Apply by Mon Jun 08 2026
1. Write a Hello World Program in Java View All →
Input: Hello World!
Output: Hello World!
Upcoming Courses
MERN Full Stack…
Starting from - June 6, 2026 4.7
Click Here for the Solution • LIVE
Java Backend…
2. Write a Program in Java to Add two Numbers. Starting from - June 6, 2026 4.6
• LIVE
Input: 2 3
DSA & System Desig…
Starting from - June 7, 2026 4.9
Output: 5 • LIVE
View All →
Click Here for the Solution
3. Write a Program to Swap Two Numbers Trending Posts
Dr B Padmaja
Input: a=2 b=5 Vector db vs. Vectorless db Vector DBs store
Output: a=5 b=2 data as high-dimensional numerical…
AMAR DEEP
Click Here for the Solution Indian IT Companies & Copilot AI Adoption
In the past six months, major Indian IT fir…
Yash Tariyal
4. Write a Java Program to convert Integer numbers 📘 GFG Connect – Post #146 | Technical
and Binary numbers. Series ⚖️ 👉 The Art of Balancing Trade…
Rukaiya
Work Experience Naukri Campus Thrilled
Input: 9 to share my participation in AINCAT 2026…
Output: 1001
GOURAV PANDEY
Day - 12: The Missing Piece of Recursion
Click Here for the Solution Backtracking = Recursion + Undo Aur ya…
View All →
5. Write a Program to Find Factorial of a Number in
Java.
Input: 5
Output: 120
Click Here for the Solution
6. Write a Java Program to Add two Complex
Numbers.
[Link] 1/7
6/4/26, 11:59 AM Java Exercises - Basic to Advanced Java Practice Programs with Solutions - GeeksforGeeks
Input: 1+2i
4+5i
Output: 5+7i
Click Here for the Solution
7. Write a Program to Calculate Simple Interest in
Java
Input : P = 10000 R = 5 T = 5
Output : 2500
Click Here for the Solution
8. Write a Program to Find Sum of Fibonacci Series
Number
Input: n = 4
Output: 33
Explaination: Sum of numbers at even indexes = 0 +
1 + 3 + 8 + 21 = 33.
Click Here for the Solution
Java Exercise on Pattern
9. Write a Program to Print the Pascal's Triangle in
Java
Input : N = 5
Output:
Click Here for the Solution
10. Write a Program to Print Pyramid Number
Pattern in Java.
pattern-2
Click Here for the Solution
11. Write a Java Program to Print Pattern.
[Link] 2/7
6/4/26, 11:59 AM Java Exercises - Basic to Advanced Java Practice Programs with Solutions - GeeksforGeeks
Pattern-3
Click Here for the Solution
12. Write a Java Program to Print Pattern.
Input : N = 5
Output:
pattern-4
Click Here for the Solution
13. Java Program to Print Patterns.
Input: number = 7
Output:
[Link] 3/7
6/4/26, 11:59 AM Java Exercises - Basic to Advanced Java Practice Programs with Solutions - GeeksforGeeks
Pattern-5
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]
Output: 28
Click Here for the Solution
15. Write a Java Program to Find the Largest
Element in Array
Input: [ 7, 2, 5, 1, 4]
Output: 7
Click Here for the Solution
16. Write Java Program to Find the Tranpose of
Matrix
Input:
[ [ 1, 2, 3 ]
[ 4, 5, 6 ]
[ 7, 8, 9 ] ]
Output:
[ [ 1, 4, 7]
[ 2, 5, 8]
[ 3, 6, 9] ]
Click Here for the Solution
17. Java Array Program For Array Rotation
Input: arr[] = {1, 2, 3, 4, 5, 6, 7}, d = 2
Output: 3 4 5 6 7 1 2
Explaination: d=2 so 2 elements are rotated to the
end of the array. So, 1 2 is rotated back
[Link] 4/7
6/4/26, 11:59 AM Java Exercises - Basic to Advanced Java Practice Programs with Solutions - GeeksforGeeks
So, Final result: 3, 4, 5, 6, 7, 1, 2
Click Here for the Solution
18. Java Array Program to Remove Duplicate
Elements From an Array
Input: [ 1, 2, 2, 3, 3, 3, 4, 5 ]
Output: [ 1, 2, 3, 4, 5 ]
Click Here for the Solution
19. Java Array Program to Remove All Occurrences
of an Element in an Array
Input: array = [ 1, 2, 1, 3, 5, 1 ] , key = 1
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]
Click Here for the Solution
String Exercises in Java
20. Java program to check whether a string is a
Palindrome
Input: "racecar"
Output: Yes
Explaination: As racerar after reversing becomes
racecar. As Reverse of String is same as String so it is
Palindrome
Click Here for the Solution
21. Java String Program to Check Anagram
Input: str1 = "Silent"
str2 ="Listen"
Output: Strings are Anagram
Explaination: 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.
Click Here for the Solution
22. Java String Program to Reverse a String
Input: str= "Geeks"
Output: "skeeG"
Click Here for the Solution
23. Java String Program to Remove leading zeros
[Link] 5/7
6/4/26, 11:59 AM Java Exercises - Basic to Advanced Java Practice Programs with Solutions - GeeksforGeeks
Input : 00000123569
Output : 123569
Click Here for the Solution
Java Practice Problems for Searching
Algorithms
24. Write a Java Program for Linear Search.
Time Complexity: O(N)
Space Complexity: O(N)
Click Here for the Solution
25. Write a Binary Search Program in Java.
Time Complexity: O(logN)
Space Complexity: O(N)
Click Here for the Solution
Practice Problems in Java Sorting
Algorithms
26. Java Program for Bubble Sort.
Time Complexity: O(N 2 )
Space Complexity: O(1)
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 logN)
Space Complexity: O(N)
Click Here for the Solution
30. Java Program for QuickSort.
[Link] 6/7
6/4/26, 11:59 AM Java Exercises - Basic to Advanced Java Practice Programs with Solutions - GeeksforGeeks
Time Complexity: O(N logN)
Space Complexity: O(1)
Click Here for the Solution
Comment K kartik 54
Article Tags: Java Java Programs
Output of Java Program Java-Library +8 More
Company Explore Tutorials Courses Preparation
About Us POTD Programming ML and Data Corner
Corporate & Communications Address: Legal Practice Languages Science Interview
Privacy Policy Problems DSA DSA and Corner
A-143, 7th Floor, Sovereign Corporate
Tower, Sector- 136, Noida, Uttar Careers Connect Web Placements Aptitude
Pradesh (201305) Contact Us Blogs Technology Web Puzzles
Corporate Upskill AI, ML & Data Development GfG 160
Registered Address:
Solution Courses Science Data Science System Design
K 061, Tower K, Gulshan Vivante Campus DevOps Programming
Apartment, Sector 137, Noida, Gautam
Training CS Core Languages
Buddh Nagar, Uttar Pradesh, 201305
Program Subjects DevOps &
GATE Cloud
School GATE
Subjects MongoDB
Software and Certifications
Tools
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
[Link] 7/7