You are on page 1of 1

import javax.swing.

JOptionPane;
public class Prime {
public static void main(String[] args) {
String input = JOptionPane.showInputDialog("number = ");
int number = Integer.parseInt(input);
int i,i1,counter;
i = 0;
counter = 0;
while (i++ < number) {
i1 = (int) Math.ceil(Math.sqrt(i));
boolean isPrime = false;
while (i1 > 1)
{
if ((i != i1) && (i % i1 == 0))
{
isPrime = false;
break;
}
else if (!isPrime)
{
isPrime = true;
}
i1--;
}
if (isPrime)
{
System.out.println(i);
counter++;
}
}

}
}

You might also like