I have to find the next prime number after a given number, but I stuck. Can you help me with for loop? I think there's a problem. I tried to find on the internet but I need the simplest possible solution :(
public static boolean prime(int num) {
for (int i = 2; i < Math.sqrt(num); i++) {
if (num % i == 0) {
return false;
}
}
return true;
}
public static void main(String[] args) {
int a = 7;
a += 1;
for (int i =a; i < 100; i++) {
if (prime(i)) {
System.out.println("the next prime number is "+i);
break;
}
}