package Prog;
import java.util.Scanner;
public class PrimeNo
{
public static void main(String a[])
{
System.out.println("Enter no. to verify, prime or not");
Scanner sc=new Scanner(System.in);
int n= sc.nextInt();
boolean isP=true;
for(int i=2; i<n/2; i++)
{
if (n%i==0)
{
System.out.println("No is not prime");
isP=false;
break;
}
}
if (isP)
{
System.out.println(" No is prime");
}
}
}
Output:
--------------------------------------------------------------------------------------------------------------------------
Enter no. to verify
15
No is not prime
import java.util.Scanner;
public class PrimeNo
{
public static void main(String a[])
{
System.out.println("Enter no. to verify, prime or not");
Scanner sc=new Scanner(System.in);
int n= sc.nextInt();
boolean isP=true;
for(int i=2; i<n/2; i++)
{
if (n%i==0)
{
System.out.println("No is not prime");
isP=false;
break;
}
}
if (isP)
{
System.out.println(" No is prime");
}
}
}
Output:
--------------------------------------------------------------------------------------------------------------------------
Enter no. to verify
15
No is not prime
0 Comments