📚 Java Technical Interview Q&A : All Programs & Explanations #3
Unanswered
hirenpatel1903
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
📚 Java Technical Interview Q&A : All Programs & Explanations
Master essential Java interview questions with clear explanations and practical program examples to strengthen your concepts and boost your confidence.
1. Reverse a String
This program reverses the input string "Automation" by using StringBuilder (which is mutable) and its reverse() method, then prints the reversed string. It's concise and runs in O(n) time and O(n) extra space for the reversed result.
Example Input
Output
2. Check for Palindrome
This Java program checks whether a given string is a palindrome or not.
A palindrome is a string that reads the same backward as forward, such as "madam", "racecar", or "level".
Example Input
Output
3. Fibonacci Series
This Java program prints the Fibonacci series up to n terms.
The Fibonacci series is a sequence of numbers where each number is the sum of the two preceding ones. It typically starts with 0 and 1.
Example Input
Output
4. Factorial of a Number
This Java program calculates the factorial of a given number.
The factorial of a number n (denoted as n!) is the product of all positive integers from 1 to n.
Example Input
Output
5. Prime Number Check
This Java program checks whether a given number is a prime number or not.
A prime number is a number greater than 1 that has no divisors other than 1 and itself.
Example Input
Output
6. Count Vowels and Consonants
This Java program counts the number of vowels and consonants in a given string.
Example Input
Output
7. Sort an Array
This Java program sorts an array of integers in ascending order.
Example Input
Output
8. Merge Two Arrays
This program demonstrates how to merge two integer arrays into a single array in Java. It uses System.arraycopy to copy elements from both arrays into a new array.
Example Input
Output
9. Find the Largest Element in an Array
This program finds the largest element in a given integer array. It initializes the largest element as the first element of the array and then iterates through the array, updating the largest element whenever a bigger number is found. Finally, it prints the largest number.
Example Input
Output
10. Remove Duplicates from an Array
This program demonstrates how to remove duplicate elements from an array using a HashSet in Java. A HashSet automatically ensures that all elements are unique.
Example Input
Output
11. Check if a Number is Armstrong
This program checks whether a given number is an Armstrong number. An Armstrong number of three digits is a number whose sum of the cubes of its digits is equal to the number itself.
Example Input
Output
12. Reverse a Number
Write a Java program to reverse the digits of a given integer. The program should take an integer, reverse its digits, and print the reversed number.
Example Input
Output
13. Calculate GCD of Two Numbers
Write a Java program to calculate the Greatest Common Divisor (GCD) of two integers using the Euclidean algorithm. The program should take two integers as input and print their GCD.
Example Input
Output
14. Check for Anagram
Write a Java program to check whether two strings are anagrams of each other. Two strings are anagrams if they contain the same characters in a different order. The program should print true if they are anagrams, otherwise false.
Example Input
Output
15. Count the Number of Digits in a Number
Write a Java program to count the number of digits in a given integer. The program should print the total count of digits.
Example Input
Output
16. Print the Prime Numbers in a Range
Write a Java program to print all prime numbers within a given range. A prime number is a number greater than 1 that has no positive divisors other than 1 and itself.
Example Input
Output
17. Find the Second Largest Element in an Array
Write a Java program to find the second largest element in an array of integers. The program should handle arrays with duplicate values as well.
Example Input
Output
18. Swap Two Numbers
Write a Java program to swap the values of two numbers without using a temporary variable.
Example Input
Output
19. Print the Pascal's Triangle
Write a Java program to print Pascal's Triangle up to a given number of rows. Each number in the triangle is the sum of the two numbers directly above it.
Example Input
Output
Example Input2
Output2
Example Input3
Output3
📝 How to Use This Repository
✔ Use this list for interview preparation
✔️ Practice each topic with examples
✔️ Contribute improvements via Pull Request
✔️ Share with your friends or students
🌐 Follow & Subscribe
Stay connected and support us online:
📊 Live YouTube Statistics
👉 Subscribe here: https://www.youtube.com/@einzigartige_/
Beta Was this translation helpful? Give feedback.
All reactions