0% found this document useful (0 votes)
31 views1 page

Java Exp 10

The document illustrates a Java program that checks whether a given number (N) is prime or not. It uses a loop to determine if N is divisible by any number from 2 to N/2, setting a flag if it finds a divisor. The program then outputs whether N is a prime number based on the flag's value.

Uploaded by

Prasad Kalal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
31 views1 page

Java Exp 10

The document illustrates a Java program that checks whether a given number (N) is prime or not. It uses a loop to determine if N is divisible by any number from 2 to N/2, setting a flag if it finds a divisor. The program then outputs whether N is a prime number based on the flag's value.

Uploaded by

Prasad Kalal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

// ILLUSTRATE A JAVA PROGRAM TO CHECK WHETHER A NUMBER IS PRIME OR NOT

class Prime

public static void main(String [] args)

int N = 4;

int flag = 0;

for (int i = 2; i <= N/2; ++i)

if (N%i==0)

flag = 1;

break;

if (flag == 1)

[Link](N+" is not a prime number");

else

[Link](N+" is a prime number");

OUTPUT:-

You might also like