Krivalar Tutorials 
Krivalar Tutorials


Find If Prime Number - Java Program

Prime number is a number which is divisible only by 1 and itself. For example, 1,3,5,7,11,13,17,19,23 are prime numbers only by 1 and itself.



public class FindIfPrimeNumber {
	public static void main (String args[]) {
		int num1=997;
		int i;
		int midValue=(num1 + 1 )/2;

		for(i=midValue; i>=2; i--){
			if((num1 % i) ==0 ) {
				break;
			}
		}

		if(i==1) {
			System.out.println(num1 + " is a Prime Number");
		}
		else {
			System.out.println(num1 + " is Not a Prime Number");
		}
	}
}


























Searching using Binary Search Tree