Code:
import java.io.*;
public class Primzahl
{
public static void main(String argv[])throws IOException
{
int ganzZahl, teiler = 2, rest;
boolean istPrim;
BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
System.out.println("Primzahlpruefung");
System.out.print("Ganze Zahl eingeben: ");
ganzZahl = Integer.parseInt(input.readLine());
istPrim = true;
while ((teiler * teiler) <= ganzZahl)
{
rest = ganzZahl % teiler;
if (rest > 0) istPrim = false;
teiler++;
}
if (istPrim) System.out.println("Die Zahl " + ganzZahl + " ist eine Primzahl. ");
else System.out.println("Die Zahl " + ganzZahl + " ist keine Primzahl. ");
}
}