//Prime no:
import java.util.Scanner;
public class Prime {
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter a no:");
int no=sc.nextInt();
if(no<1)
System.out.println("Can not determine");
else if(no==2)
System.out.println("It is a prime no.");
else
{
int p=1;
for(int i=2;i<no;i++)
{
if(no%i==0)
{
p=0;break;
}
}
if(p==1)
System.out.println("It is a prime no.");
else
System.out.println("It is not a prime no.");
}
}
}
import java.util.Scanner;
public class Prime {
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter a no:");
int no=sc.nextInt();
if(no<1)
System.out.println("Can not determine");
else if(no==2)
System.out.println("It is a prime no.");
else
{
int p=1;
for(int i=2;i<no;i++)
{
if(no%i==0)
{
p=0;break;
}
}
if(p==1)
System.out.println("It is a prime no.");
else
System.out.println("It is not a prime no.");
}
}
}
No comments:
Post a Comment