Results 1 to 9 of 9

Thread: prime numbers

  1. #1
    Daniel93 is offline Member
    Join Date
    Jan 2013
    Posts
    3
    Rep Power
    0

    Default 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 );
    }
    }
    }

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,902
    Rep Power
    25

    Default 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.

  3. #3
    Daniel93 is offline Member
    Join Date
    Jan 2013
    Posts
    3
    Rep Power
    0

    Default Re: prime numbers

    thats the thing it literally says " error: cannot find symbol" line 6. im using jcreator if that makes a difference?

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default 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?

  5. #5
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,902
    Rep Power
    25

    Default 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;
             ^
    Notice where the ^ is and also that var is pointed out as the symbol in the text of the message
    If you don't understand my response, don't ignore it, ask a question.

  6. #6
    Daniel93 is offline Member
    Join Date
    Jan 2013
    Posts
    3
    Rep Power
    0

    Default 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 + " ");
    }
    }


    }
    }
    }

  7. #7
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,902
    Rep Power
    25

    Default 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.

  8. #8
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,783
    Blog Entries
    7
    Rep Power
    21

    Default Re: prime numbers

    What's the space doing between 'is' and 'prime'? Spaces are not allowed in method names.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  9. #9
    Russd772 is offline Member
    Join Date
    Dec 2012
    Posts
    42
    Rep Power
    0

    Default 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 + " ");
        }
        }
    
    
        }
        }
        }
    if you have other classes that your using with this code it would be helpfull to see them as well, i hope this helps somewhat

Similar Threads

  1. Count Prime Numbers
    By niloufar in forum New To Java
    Replies: 1
    Last Post: 10-18-2012, 07:18 AM
  2. Prime Number - System print all the prime numbers ...
    By pinkdreammsss in forum New To Java
    Replies: 20
    Last Post: 04-26-2009, 02:50 AM
  3. prime numbers program
    By i contra i in forum New To Java
    Replies: 9
    Last Post: 01-15-2009, 08:22 AM
  4. Prime numbers
    By tercius in forum New To Java
    Replies: 3
    Last Post: 05-04-2008, 07:05 AM
  5. Prime numbers
    By gapper in forum New To Java
    Replies: 3
    Last Post: 02-07-2008, 11:09 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •