Prime number exercise in Java

Good morning guys.

Following the Java course, I had to do an exercise to check if a number is prime or not. I wrote the following code. I used a scanner because I want the user to enter a number and then we analyse it and return whether it’s prime or not. I can’t get it to work. I’m using NetBeans and when I compile the file it gives me no error but it still doesn’t work.

Any help would be appreciated. Thanks in advance. The error I get is this one:

Error: Could not find or load main class PrimeDirective

package primedirective;

import java.util.Scanner;

public class PrimeDirective {

    public boolean isPrime(int number){
        Scanner sc = new Scanner(;
        System.out.println("Give me a number");
        int a = sc.nextInt();
        System.out.println("The number given by the user is " + a);
        if (a / 1 !=0 && a / a !=0){
          System.out.print("It's a prime number");
        } else {
          System.out.println("It's not a prime number");
        return false;         
    public static void main(String[] args) {}  

Make sure all instances of PrimeDirective are capitalised appropriately.

don’t forget to call isPrime with an integer argument in the main method.

1 Like