I'm trying to write a coding that will be able to determine if a number keyed-in is a Prime Number or not.
Here's what I did:
public class PrimeNumber
{
public static void main(String args[])
{
int n;
Scanner Prime = new Scanner(System.in);
System.out.println(" Please enter a number: ");
n = Prime.nextInt();
boolean isPrime(int n) {
if (n%2==0) return false;
for(int i=3;i*i<=n;i+=2) {
if(n%i==0)
return false;
}
return true;
}
}
}
And here's all the errors that appear:
PrimeNumber.java:13: error: ';' expected
boolean isPrime(int n) {
^
PrimeNumber.java:13: error: ';' expected
boolean isPrime(int n) {
^
2 errors
Can someone please shed some light on finishing this coding the CORRECT way? Please and thanks in advance!