java program to check whether the given number is prime or not

import java.util.*;
public class IsPrime
{
    public static void main(String[] args)
    {
        Scanner sc=new Scanner(System.in);
        boolean flag=true;
        int n=sc.nextInt();
        if(n>=2)
        {
            for(int i=2;i<n;i++)
            {
                if(n%i==0)
                  flag=false;
            }
            if(flag)
              System.out.println("is prime");
            else
                     System.out.println("not prime");
           
        }
       
    }
}

Comments

Popular posts from this blog

Small virus code to hang your friend's system

How to use Remote Desktop