Top 10 most common Java Interview Programming Questions

In almost all interview these programming questions are asking by interviewer.

 

1. Check Number is Prime number or not.

package practice.Number;

public class PrimeNumber {
	public static void main(String Ars[]) {
		int i, m = 0, flag = 0;
		int n = 5;
		m = n / 2;
		if (n == 0 || n == 1) {
			System.out.println(n + " " + "Not prime number");
		} else {
			for (i = 2; i <= m; i++) {
				if (n % i == 0) {
					System.out.println(n + " " + "Not prime number");
					flag = 1;
					break;
				}
			}
			if (flag == 0) {
				System.out.println(n + " " + "is prime number");
			}
		}
	}
}

 

2. Reverse number in java.


package practice.Number; public class ReverceNumber { public static void main(String[] args) { int n = 123; int r = 0; while (n > 0) { int m = n % 10; n = n / 10; r = r * 10 + m; } System.out.println("Reverce number of number is " + r); } }

 

3. Remove Duplicates number.


package practice.Number; import java.util.ArrayList; import java.util.HashSet; import java.util.List; import java.util.Set; public class RemovedDuplicates { public static void main(String[] args) { List<Integer> al= new ArrayList<Integer>(); al.add(1); al.add(2); al.add(3); al.add(3); al.add(4); al.add(5); System.out.println(al); Set<Integer> hs= new HashSet<Integer>(al); System.out.println(hs); } }

 

4. Check Palindrome Number.


package practice.Number; public class PalindromeNumber { public static void main(String Arg[]) { int n = 121; int temp = n; int sum = 0; while (n > 0) { int m = n % 10; n = n / 10; sum = (sum * 10 )+ m; } if (sum == temp) { System.out.println(sum + " number is palindrome"); } else { System.out.println(sum + " number is not palindrome"); } } }

 

5. Missing Number from Array.


package practice.Number; public class MissingNumber { static int getMissingNumber(int num[], int n) { int i, total; total = (n + 1) * (n + 2) / 2; for (i = 0; i < n; i++) { total -= num[i]; } return total; } public static void main(String[] args) { int num[] = {1, 2, 3, 4, 5, 6, 8, 9 }; int miss = getMissingNumber(num, num.length); System.out.println(miss); } }

 

6.Fibonacci Series.

Fibonacci series without Recursion.


package practice.Number; public class FibonacciSeries { public static void main(String Arg[]) { int n=10, n1=0, n2=1,n3; System.out.print(n1+" "+n2); for(int i=2;i<n;i++) { n3=n1+n2; System.out.print(" "+ n3); n1=n2; n2=n3; } } }

 

Fibonacci series with Recursion.


package practice.Number; public class FibonacciSeriesRecursion { static int i, n1=0,n2=1,n3; static void printFibonaicc(int n) { if(n>0) { n3= n1+n2; n1=n2; n2=n3; System.out.print(" "+n3); printFibonaicc(n-1); } } public static void main(String Ags[] ) { int n=10; System.out.print(n1+" "+n2); printFibonaicc(n-2); } }

 

7. Check Armstrong Number.


package practice.Number; public class Armstrongnumber { public static void main(String[] args) { int n = 153; int s = 0, temp = 153; while (n > 0) { int m = n % 10; n = n / 10; s = s + (m * m * m); } if (temp == s) { System.out.println("Number is Armstrong"); } else { System.out.println("Number is not Armstrong"); } } }

 

8. Factorial Number.


package practice.Number; public class Factorial { public static void main(String[] args) { int n=5; int f = 1; while(n>0) { f=(f*n); n--; } System.out.println("Factorial of n : "+f); } }

 

9. Square Root of Number.


package practice.Number; public class SquareRoot { public static void main(String[] args) { Double num = 4.0; int n = 4; System.out.println("SquareRoot of number is : " + Math.sqrt(num)); System.out.println("SquareRoot of number is : " + Math.pow(num, 2)); System.out.println("SquareRoot of number is : " + Math.pow(num, 3)); for (int i = 1; i <= n; i++) { int reminder = n % i; if (reminder == 0 && (n / i) == i) {//if reminder is 0 and number divided by i is same i than number is square root System.out.println("The Square root of " + n + " is = " + i); } } } }

 

10. Print duplicate element.


package practice.Number; public class DuplicateElement { public static void main(String Arg[]) { int nums[] = { 1, 2, 3, 4, 5, 5, 6, 7 }; int l = nums.length; for (int i = 0; i < l; i++) { for (int j = i + 1; j < l; j++) { if (nums[i] == nums[j]) { System.out.println(nums[i]); } } } } }

 

Hope this was helpful for you. If you have any questions please feel free to leave a comment. Thank you for reading.

11 Replies to “Top 10 most common Java Interview Programming Questions”

  1. Needed to write you this very small word to help thank you very much yet again with the superb tips you have shown on this website. This is so unbelievably open-handed with you to provide without restraint what exactly numerous people would’ve offered for sale for an ebook to help make some money on their own, precisely seeing that you might have tried it in case you desired. Those suggestions in addition worked to become good way to realize that some people have the identical keenness similar to my personal own to realize significantly more when it comes to this matter. I believe there are several more pleasant sessions up front for people who scan your site.

  2. A lot of thanks for all your valuable efforts on this site. Kate loves getting into investigation and it’s really easy to understand why. I know all concerning the dynamic medium you give informative solutions on this web blog and as well as foster participation from others on that content plus our daughter is certainly discovering a lot. Have fun with the remaining portion of the new year. You are conducting a first class job.

  3. A lot of thanks for each of your hard work on this web page. Kim really likes going through investigation and it’s really easy to understand why. Many of us know all of the dynamic method you make powerful steps on this web blog and as well as improve participation from people on that issue so our girl is in fact learning a lot of things. Have fun with the remaining portion of the new year. You are conducting a pretty cool job.

  4. I’m also commenting to let you be aware of of the brilliant discovery my child encountered checking the blog. She came to understand a lot of details, including how it is like to have a marvelous coaching character to get folks completely fully grasp a variety of complex issues. You actually did more than her desires. I appreciate you for coming up with such essential, dependable, edifying and cool guidance on that topic to Ethel.

  5. I am also commenting to let you know of the great encounter my friend’s daughter found reading through your web page. She figured out numerous issues, not to mention what it’s like to have an amazing giving mood to have men and women really easily have an understanding of selected hard to do subject areas. You really exceeded our own expectations. Many thanks for imparting the interesting, safe, explanatory and even easy thoughts on the topic to Janet.

  6. I am commenting to let you know of the fine encounter my cousin’s daughter experienced reading your site. She even learned many issues, not to mention what it’s like to have a wonderful giving mindset to have many people quite simply grasp chosen hard to do subject areas. You really exceeded our expectations. Many thanks for giving the insightful, healthy, educational and as well as easy thoughts on the topic to Jane.

  7. Thanks for the suggestions about credit repair on this particular web-site. The things i would offer as advice to people is usually to give up this mentality that they buy at this point and fork out later. Being a society most of us tend to make this happen for many factors. This includes trips, furniture, in addition to items we’d like. However, it is advisable to separate one’s wants from the needs. As long as you’re working to raise your credit ranking score actually you need some trade-offs. For example you may shop online to economize or you can check out second hand outlets instead of high priced department stores intended for clothing.

  8. A lot of thanks for each of your hard work on this web page. Kim really likes going through investigation and it’s really easy to understand why. Many of us know all of the dynamic method you make invaluable steps on this web blog and as well as improve participation from people on that idea so our girl is certainly learning a lot of things. Have fun with the remaining portion of the new year. You are conducting a pretty cool job.

Leave a Reply

Your email address will not be published.