Printing Prime number in java

class PrimeNo{
    public static void main(String ar[]){
        int n=50;
        boolean isPrime=false;
        for(int i=3;i<=n;i++){
            for(int j=2;j<i;j++){
                if(i%j==0){ 
                    isPrime=false;
                    break;
                }
                else
                    isPrime=true;
            }
            if(isPrime)
                System.out.println(i+" is prime");
        }
    }
}
  

No comments:

Popular Posts