I am still trying to get this program to work. I checked all my brackets and they seem to be correct. I am using an object for my method call and I am still getting errors. according to what I read in my text book, the program should work. The program is below with the errors as comments.
//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".
}