This Logic of Program is simple, less coding and decrease complexity for find Prime Number.
CODING:
import java.util.Scanner;
class prime{
public static void main(String[] args){
Scanner n=new Scanner(System.in);
int num,temp=0;
System.out.print("Enter The Prime Number:");
num=n.nextInt();
for(int i=2;i<=num/2 && temp==0;i++){if(num%i==0){temp=1;}}
System.out.print(((temp==1)?"Not":"Yes")+" Prime Number");
}
}
class prime{
public static void main(String[] args){
Scanner n=new Scanner(System.in);
int num,temp=0;
System.out.print("Enter The Prime Number:");
num=n.nextInt();
for(int i=2;i<=num/2 && temp==0;i++){if(num%i==0){temp=1;}}
System.out.print(((temp==1)?"Not":"Yes")+" Prime Number");
}
}
Comments
Post a Comment