Java Program to Find Number is Prime Or Not
What is Prime Number?
A number that is greater than One and divisible only by 1 and itself
For Example: 2, 3, 5,7,11,13,17, 19……..
Example: Code Program
import java.util.*;
public class PrimeNum {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc = new Scanner(System.in);
int num, i, f = -1;
System.out.print("Enter Number:");
num = sc.nextInt();
i = 2;
while(i<num/2) {
if(num%i == 0)
f += 1;
i+=1;
}
if(f == -1)
System.out.print(num+" is
Prime");
else
System.out.print(num+" is Not
Prime");
}
}
Output:
Python Program Code
Post a Comment