The professional, friendly Java community. 21,500 members and growing!

The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.

Problems with my prime finder program

I am having trouble with my prime finder program. This program allows the user to enter a number than finds the prime of that number. Example, if you enter five it will find the 5th prime (11). I am getting two errors in my program. One in the first statement in the main method and one for final curly bracket which completes the class. I checked all my curly brackets and they seem good. I also checked the syntax of my main method and that also seems good. acording to what I read in my text book, the program should work. could anyone help me figure this out. The program is below with the errors that a got added as comments.

Thanks,
Truck35

//PrimeWorker Class
class PrimeWorker {
int i, num, counter, j;
//PrimeWorer Constructor
PrimeWorker (int b) {
num = b;
}
/* Get Prime Method is used to calculate prime numbers and keep count of every prime number
* that is produced. That number is then compared to the number entered into the
* computer by the user and returned.
*/
int get_prime() {
counter = 0;
for (i=2;;){
for (j=2; j <= i/j; j++){
if ((i%j) != 0){
counter++;
}
if (counter == num){
break;
}
}
return counter;
}
}
public class PrimeLocator {
/**
* This program will ask the user which prime number they want, find it, and return the value.
*/
/*I got the following error message "The method main cannot be declared static,
* static methods can only be declared in static or top level type".*/
public static void main(String args[])
throws java.io.IOException {
int x;
//Asks the user to enter which prime number they want to find.
System.out.println("Please enter number prime you want to find: ");
x = (int) System.in.read();
PrimeWorker number = new PrimeWorker (x);
//Displays the prime number the user wanted to find.
System.out.println("The " + x + "th prime is " + number.get_prime());
}
//Got the following error, "Syntax error, insert "}" to complete class body".
}

Re: Problems with my prime finder program

/*I got the following error message "The method main cannot be declared static,
* static methods can only be declared in static or top level type".*/
public static void main(String args[])
throws java.io.IOException {