Add

Check Prime Number Program in Java

12:02:00 PM Rohit Kumar Verma 0 Comments

Check Prime Number Program in Java

The prime number is greater than 1 and whose factors are only 2 numbers 1 and the number itself. for eg. 2 3 5 7 11...


class CheckPrime{
public static void main(String args[]){
int a,b=0,flag=0;
int input=17;
b=input/2;
 for(a=2;a<=b;a++){
  if(input%a==0){
  System.out.println("Number is not prime");
  flag=1;
  break;
  }
 }
 if(flag==0)
 System.out.println("Number is prime");
}
}

0 comments: