Prime number i nothing but , the number is divided by 1 or the same number. Today we learnt about prime number. By the above program we able to understand the program meaning.
Before doing the program we have to go though the flow chart . then only we can do the program without any confusion.
flowchart:

program:
public class PrimeNmber {
public static void main(String[]args) {
int no =1009;
int isprime=0;
int div=2;
if(no<=1) {
System.out.println(“enter valid number “);
}
else {
while(div<=no/2) {
if(no%div==0) {
isprime=1;
break;
}
div=div+1;
}
System.out.println(“how many time the loop has executed “+div);
if(isprime==0) {
System.out.println(no+” is a prime number “); }
else {
System.out.print(no+” its not a prime number”);
}
}
}
}
output:
sobhika@sobhika-HP-Laptop-15-db1xxx:~$ javac PrimeNmber.javasobhika@sobhika-HP-Laptop-15-db1xxx:~$ java PrimeNmberhow many time the loop has executed 5051009 is a prime number sobhika@sobhika-HP-Laptop-15-db1xxx:~$