Q:

How to End my Program

I'm writing a program to try and determine if a user-generate number is prime.
My Code

My Problem
The program seems to be able to tell if a number is prime or not fine. But I run into an issue when inputing non-prime numbers: it says it is not prime then it is prime, like this:

I think I could solve this if I was able to end the program in the condition brackets of my if statement. So as soon as we figure out it's not prime, we end the program. Does anyone know how to end the program in my if statement brackets?

A:

As Takendarkk said in the comment above, you could just call System.exit(0) to terminate, but if I were you, I'd just rearrange the flow of the code. 
boolean isPrime = true;
for( . . . ) {
    if( . . . ) {
        isPrime = false;
        break;
    } else {
        continue;
    }
}

if(isPrime) {
    System.out.println("It is prime!");
} else {
    System.out.println("It is not prime!");
}

I guess it doesn't really matter which way you do it. I tend to choose the second way because it makes the process repeatable and useable in other code...

A:

System.exit(0); will terminate your program.

