### 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 in Java Without Recursion

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

package com.ashu;
public class FibonacciWithoutRecursion {
public static void main(String[] args) {
int n1=0,n2=1,n3, count=10;
System.out.println(n1+""+n2);
for (int i = 2; i < count; i++) {
n3=n1+n2;
n1=n2;
n2=n3;
System.out.println(""+n3);
}
}
}

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

### 2) prime number program in java

Write a java program to check prime number.

package com.ashu;
import java.util.Scanner;
class PrimeCheck
{
public static void main(String arg[])
{
int t;
boolean isPrime=true;
Scanner scan= new Scanner(System.in);
System.out.println("Enter any number:");
//capture the input in an integer
int num=scan.nextInt();
scan.close();
for(int i=2;i<=num/2;i++)
{
t=num%i;
if(t==0)
{
isPrime=false;
break;
}
}
if(isPrime)
System.out.println(num + " is a Prime Number");
else
System.out.println(num + " is not a Prime Number");
}
}

Enter any number: 44

Output: 44 is not a Prime Number

Enter any number: 7

Output: 7 is a 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.

### 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