Wednesday, 15 June 2016

How to check whether the given number is prime number or not


public class PrimeNumber_Or_Not {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
int x;
{
    for(x=2;x<=10;x++)
        if(x%2==0)
        {
            System.out.println("not prime" + x);
           
        }
    else {
        System.out.println("prime " + x);
    }
}
    }

   
   
}
Output:
not prime2
prime 3
not prime4
prime 5
not prime6
prime 7
not prime8
prime 9
not prime10

No comments:

Post a Comment