Results 1 to 9 of 9
Thread: prime numbers
 01062013, 06:52 PM #1Member
 Join Date
 Jan 2013
 Posts
 3
 Rep Power
 0
prime numbers
im kinda new to programming and java. i have an assignment due for tomorrow and im trying to go by this step by step but keep getting the error " cant find symbol "? the error points to the line " if ( isPrime ( i ) ) " i dont know what to add in and where? any help is much appreciated! thanks :)
public class prime{
public static void main ( String[] args ){
for ( int i = 2; i <= 1000; i++ ){
if ( isPrime ( i ) )
System.out.println ( i );
}
}
}
 01062013, 06:56 PM #2
Re: prime numbers
What is the symbol in the error message that the compiler can not find?
If you don't understand my response, don't ignore it, ask a question.
 01062013, 06:59 PM #3Member
 Join Date
 Jan 2013
 Posts
 3
 Rep Power
 0
Re: prime numbers
thats the thing it literally says " error: cannot find symbol" line 6. im using jcreator if that makes a difference?

Re: prime numbers
Usually the error will comprise several lines with a small hat symbol, ^, under the line marked as error, indicating which token is in error. Do you see any more information in your error message? And does your class have an isPrime(int i) method?
 01062013, 07:12 PM #5
Re: prime numbers
Is there a ^ under any part of the line?
Here is a sample from the javac compiler:
Java Code:TestSorts.java:138: cannot find symbol symbol : variable var location: class TestSorts var = 2; ^
If you don't understand my response, don't ignore it, ask a question.
 01062013, 07:24 PM #6Member
 Join Date
 Jan 2013
 Posts
 3
 Rep Power
 0
Re: prime numbers
no i didnt have the isPrime method in. thanks :) but now is has to errors. saying
error: ')' expected
error: ';' expected
both on the same line. " if ( is prime (i)){ "
heres the code now. thanks for the help :)
public class AS3Q4 {
public static boolean isPrime(int i) {
for(int i= 2; i<1000; i++){
if ( is prime (i)){
if(number%i == 0){
System.out.println(i + " ");
}
}
}
}
}
 01062013, 07:43 PM #7
Re: prime numbers
Without the full text of the error messages that shows where the errors are located, it is hard to help.
Can you use the javac command to compile your program? It gives good error messages that say where the error is located.
See the example in my last post.
Also Please edit your post and wrap your code with
[code]
<YOUR CODE HERE>
[/code]
to get highlighting and preserve formatting.If you don't understand my response, don't ignore it, ask a question.
 01062013, 08:24 PM #8
 Join Date
 Sep 2008
 Location
 Voorschoten, the Netherlands
 Posts
 14,292
 Blog Entries
 7
 Rep Power
 24
Re: prime numbers
What's the space doing between 'is' and 'prime'? Spaces are not allowed in method names.
kind regards,
JosThe only person who got everything done by Friday was Robinson Crusoe.
 01062013, 08:33 PM #9Member
 Join Date
 Dec 2012
 Posts
 42
 Rep Power
 0
Re: prime numbers
i would start with that line and make sure you dont have extra spaces and everything is written correctly. remember java is case sensitive so having a capitol letter in one place it expects that when you use that method you will write it exactly as you did before. it looks like multiple errors in your method for determining your prime number as well,
Java Code:public class AS3Q4 { // here you declare the method isPrime() and ask for parameters of i; // also should be public void unless your intending to return a value from this method public static boolean isPrime(int i) { // here you assign int i which is already used so you would need a different variable name for(int i= 2; i<1000; i++){ // next line "is prime" is a reference to the above method? which is spelled wrong should be isPrime(i) // also i don't think that you would generally call the method your using inside itself? // i could be wrong about that i'm sure someone will correct me. if ( is prime (i)){ // here your using a variable that has not been declared yet so the compiler // will have no idea what your trying to do. if(number%i == 0){ System.out.println(i + " "); } } } } }
Similar Threads

Count Prime Numbers
By niloufar in forum New To JavaReplies: 1Last Post: 10182012, 06:18 AM 
Prime Number  System print all the prime numbers ...
By pinkdreammsss in forum New To JavaReplies: 20Last Post: 04262009, 01:50 AM 
prime numbers program
By i contra i in forum New To JavaReplies: 9Last Post: 01152009, 08:22 AM 
Prime numbers
By tercius in forum New To JavaReplies: 3Last Post: 05042008, 06:05 AM 
Prime numbers
By gapper in forum New To JavaReplies: 3Last Post: 02072008, 11:09 AM
Bookmarks