Print Prime Number Program in Java
Prime number is only divisible by 1 and number it self. Whenever you write code in java for print prime number follow this concept.
Example of Print Prime Number Program in Java
class PrimeNumberExample
{
public static void main(String args[])
{
int i,m=0,flag=0;
int no=19;
m=no/2;
for(i=2;i<=m;i++){
if(n%i==0){
System.out.println("Number is not prime");
flag=1;
break;
}
}
if(flag==0)
System.out.print(no);
System.out.println(" is Prime Number");
}
}
Output
19 is Prime Number
Reference:
No comments :
Post a Comment