Javatpoint Logo
Javatpoint Logo

Java Programs

Java programs are frequently asked in the interview. These programs can be asked from control statements, array, string, oops etc. Let's see the list of java programs.


1) Fibonacci series

Write a java program to print fibonacci series without using recursion and using recursion.

Input: 10

Output: 0 1 1 2 3 5 8 13 21 34


2) Prime number

Write a java program to check prime number.

Input: 44

Output: not prime number

Input: 7

Output: prime number


3) Palindrome number

Write a java program to check palindrome number.

Input: 329

Output: not palindrome number

Input: 12321

Output: palindrome number


4) Factorial number

Write a java program to print factorial of a number.

Input: 5

Output: 120

Input: 6

Output: 720


5) Armstrong number

Write a java program to check Armstrong number.

Input: 153

Output: Armstrong number

Input: 22

Output: not Armstrong number



Java Sorting Programs

6) Bubble Sort

Write a java program to sort an array elements using bubble sort algorithm.

Input: 18 9 33 4 84 32

Output: 4 9 18 32 33 84


7) Selection Sort

Write a java program to sort an array elements using selection sort algorithm.

Input: 18 9 33 4 84 32

Output: 4 9 18 32 33 84


8) Insertion Sort

Write a java program to sort an array elements using insertion sort algorithm.

Input: 18 9 33 4 84 32

Output: 4 9 18 32 33 84


Java Searching Programs

9) Linear Search

Write a java program to perform linear search in java.


10) Binary Search

Write a java program to perform binary search in java.


Java Array Programs

11) Find 3rd Largest Number in an Array

Write a java program to find 3rd largest number in an array.

Input: 1,2,5,6,3,2

Output: 3


12) Find 2nd Largest Number in an Array

Write a java program to find 2nd largest number in an array.

Input: 1,2,5,6,3,2

Output: 5


13) Find Largest Number in an Array

Write a java program to find largest number in an array.

Input: 1,2,5,6,3,2

Output: 6


14) Find 2nd Smallest Number in an Array

Write a java program to find 2nd smallest number in an array.

Input: 1,2,5,6,3,2

Output: 2


15) Find Smallest Number in an Array

Write a java program to find smallest number in an array.

Input: 1,2,5,6,3,2

Output: 1


16) Remove Duplicate Element in an Array

Write a java program to remove duplicate element in an array.

Input: 10,20,20,30,30,40,50,50

Output: 10 20 30 40 50


17) Add Two Matrices

Write a java program to add two matrices.

Input:

First matrix elements:
1 1 1
2 2 2
3 3 3
Second matrix elements:
1 1 1
2 2 2
3 3 3

Output:

Addition of the matrix:
2 2 2
4 4 4
6 6 6

18) Multiply Two Matrices

Write a java program to multiply two matrices.

Input:

First matrix elements:
1 1 1
2 2 2
3 3 3
Second matrix elements:
1 1 1
2 2 2
3 3 3

Output:

Multiplication of the matrix:
6 6 6
12 12 12
18 18 18

19) Print Odd and Even Number from an Array

Write a java program to print odd and even number from an array.

Input: 1,2,5,6,3,2

Output:

Odd Numbers:
1
5
3
Even Numbers:
2
6
2

20) Transpose matrix

Write a java program to transpose a matrix.

Output:

Printing Matrix without transpose:
1 3 4 
2 4 3 
3 4 5 
Printing Matrix After Transpose:
1 2 3 
3 4 4 
4 3 5 
Next TopicJava OOPs Concepts


Please Share

facebook twitter google plus pinterest tumbler

Learn Latest Tutorials