Bilginize,
public class Main {
public static void main(String[] args) {
while(true){
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.print("Enter value for prime!!! : ");
String value = br.readLine();
try{
int candidateValueOfPrimeNumberAsInt = Integer.parseInt(value);
bool isPrime = isPrime(candidateValueOfPrimeNumberAsInt);
if(isPrime){
System.out.print("Primeee -> " + candidateValueOfPrimeNumberAsInt);
break;
}
System.out.print("Not Primeee, Try again! -> " + candidateValueOfPrimeNumberAsInt);
}catch(NumberFormatException nfe){
System.err.println("Value is not numeric! Retry again.");
}
}
}
private static isPrime(int candidateOfprimeNumber){
int counter = 0;
for (int index = 1; index <= candidateOfprimeNumber; index++) {
if (candidateOfprimeNumber % index == 0) {
counter++;
}
}
return counter <= 2;
}
}