Java Program to Print Prime numbers between 1 to n using while loop
Java
public class Main
{
public static void main(String[] args) {
int n = 10,i=2,j;
while(i<=n){
boolean isPrime=true;
j=2;
while(j*j<=i){
if(i%j==0){
isPrime=false;
break;
}
j++;
}
if(isPrime){
System.out.println(i+" prime");
}else{
System.out.println(i+ "not prime");
}
i++;
}
}
}