0% found this document useful (0 votes)
17 views

Import Java.util.Scanner;

Uploaded by

anshul.k.002414
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views

Import Java.util.Scanner;

Uploaded by

anshul.k.002414
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

import java.util.

Scanner;

public class prime


{

public static void main(String[] args) {


int n;
System.out.println("Enter the number : ");
Scanner sc = new Scanner(System.in);
n = sc.nextInt();

boolean isprime;
isprime = false;

if (n < 2) {
isprime = false;
}
else
{
int i = 2;
while (i <= Math.sqrt(n))
{
if (n % i == 0)
{
isprime = false;
break;
}
i++;
}
}

if (isprime) {
System.out.println("Prime Number");
}
else
{
System.out.println("Not a prime number !");
}

sc.close();
}
}

You might also like