English, asked by suzi21, 1 year ago

write a prgrm. to check a no is prime or not.​

Answers

Answered by jainishpjain
0

class Prime

{

public static void main (int a )

{

for(int i = 1 ; i <= a ; ++a)

{

if (a%i == 0)

{ ++c;}

}

if(c == 2)

{

System.out.println("prime number");

}

else

{

System.out.println("Not a prime number");

}

}

}

Answered by BrainlyPromoter
0

public class PrimeBrainly

{

~~public static void main(int n)

~~{

~~~~ int c = 1;

~~~~ int i = 0;

~~~~ while(c < = n)

~~~~ {

~~~~ if(n ℅ c == 0 )

~~~~ i++;

~~~~ }

~~~~ if(i == 2)

~~~~ System.out.println("Yes, the given number is a prime number.");

~~~~ else

~~~~ System.out.println("No, the given number is not a prime number.");

~~ }

}

Know more

A prime number is a number which has only two factors in all, which is necessarily one and itself.

For example, 3

Similar questions