Computer Science, asked by Anonymous, 5 months ago

WAP to accept a number and check if it is a prime number​

Answers

Answered by BrainlyProgrammer
1

Answer:

import java.util.*;

class PrimeCheck

{

   public static void main(String ar[])

   {

       Scanner sc=new Scanner (System.in);

       System.out.println("Enter a no.");

       int c=0,i,n=sc.nextInt();

       for(i=1;i<=n;i++)

       {

           if(n%i==0)

           c++;

       }

       if (c==2)

       System.out.println("Prime");

   }

}

  • For verification please see the above attachment

Attachments:
Answered by kavitasingh1234
4

Answer:

import java.until.*;

class prime_number

{

public static void main (String args[])

{

Scanner sc=new Scanner (System.in);

int c=0;

{

System.out.println ("Enter a number");

int n=sc.nextInt();

for (i=1;i<=n;i++)

{

if (n%i==0)

c++;

}

if(c==2)

System.out. println ( n+ "Is a prime number");

else

System.out.println(n+ " Is not a prime number ");

}

}

Output

3

Input

3 is a prime number

Similar questions