Supposed to write a program using methods that utilizes a checker for prime numbers and then returns a true or false statement. I belive I have screwed this program up bad but im on the right side of the ball at least.
CODE
/**
* DJ Hill
* Computer Science Ap Online course
* Gary Langner
* OS Vista / Programmer BlueJ
*/
import java.util.*;
import java.text.*;
public class primenumber
{
public static boolean isPrime(int n)
{ boolean prime = true;
for (int i = 3; i <= Math.sqrt(n); i += 2)
if (n % i == 0)
{
prime = false;
break;
}
if (( n%2 !=0 && prime && n > 2) || n == 2)
{
return true;
}
else
{
return false;
}
}
public static void main (String[] args)
{
Scanner in=new Scanner(System.in);
System.out.println("Please input a number you wish to test if it is prime.");
int n=in.nextInt();
isPrime(int n);
}
}
What I am having problems with at the moment is when you try to initialize the compile it will say that isPrime(int n); does not have a .class and needs something, and I dont knwo what.