/* This Program finds prime numbers upto the number entered by the user.
*/
import javax.swing.JOptionPane;
public class Primefinder {
public static void main (String args[]) {
String PrimeCounter =
JOptionPane.showInputDialog("Enter maximum of prime numbers");
int primecounter =Integer.parseInt (PrimeCounter);
int prime = 2;
String columnmaker = " |";
while (primecounter>=0) {
boolean primechecker = true;
int divisor = 2;
int root = ((int)Math.sqrt(prime));
while (divisor<=root) {
int remainder = prime % divisor;
if (remainder==0) {
primechecker =false;
divisor=prime;
}
divisor++;
}
if(primechecker) {
columnmaker = columnmaker + prime + "| |";
}
primecounter--;
prime++;
}
System.out.println (columnmaker);
}
}
No comments:
Post a Comment