Trying to create a Prime Number Tester like the code below but when I input java isPrime(9)
in the terminal window, I get
-bash: syntax error near unexpected token `('
I want the code to read either true
or false
back to me.
Can someone also explain to me the function of the main method
as I guess my user input is first captured by the main method
and then passed on to any other referenced methods. Or is it a matter of placement of the main method
in the code, that is to put the main method
at the top (or is this irrelevant in java)?
Here is the code.
public class isPrime {
public static boolean isPrime(int N){
for (int i=3; i == N/2; i++){
if (N%i==0)
return true;
}
return false;
}
public static void main (String [] args){
int N = Integer.parseInt(args[0]);
System.out.println(isPrime(N));
}
}