Welcome to the Java Programming Forums


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.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 6 of 6

Thread: Help please!

  1. #1
    Junior Member
    Join Date
    Sep 2010
    Posts
    3
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Help please!

    here is my code:

    package program3;
     
     
    public class caesarCipher {
     
        public static void main(String[] userString) {  //userString is the string supplied by the user as an argument
     
            rot13(userString);  //call method rot13 to apply the caesar cipher on the string
            System.exit(0); //exit program
     
     
        }
     
        private static void rot13(String[] userString) {
     
            char[] rot = new char[10];
            rot = userString.toCharArray();   //stores the character from the string currently being ciphered
     
     
     
            }
    }

    Netbeans gives me an error: "cannot find symbol". I googled a bit and from my understanding it is an issue with class names and the static modifier. I could just copy paste code from there and make it work, but can someone please explain the nuances behind this?
    PS : program isn't finished yet

  2. #2
    Member
    Join Date
    Jun 2010
    Posts
    75
    Thanks
    7
    Thanked 1 Time in 1 Post

    Default Re: Help please!

    Quote Originally Posted by jeeba View Post
    here is my code:

    package program3;
     
     
    public class caesarCipher {
     
        public static void main(String[] userString) {  //userString is the string supplied by the user as an argument
     
            rot13(userString);  //call method rot13 to apply the caesar cipher on the string
            System.exit(0); //exit program
     
     
        }
     
        private static void rot13(String[] userString) {
     
            char[] rot = new char[10];
            rot = userString.toCharArray();   //stores the character from the string currently being ciphered
     
     
     
            }
    }

    Netbeans gives me an error: "cannot find symbol". I googled a bit and from my understanding it is an issue with class names and the static modifier. I could just copy paste code from there and make it work, but can someone please explain the nuances behind this?
    PS : program isn't finished yet
    You should read the documentation on the String class. Check that you are actually using a method that is defined for the class.

  3. #3
    Junior Member
    Join Date
    Sep 2010
    Posts
    3
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: Help please!

    It is listed as a valid method over here. Is my implementation wrong?

  4. #4
    Member
    Join Date
    Jun 2010
    Posts
    75
    Thanks
    7
    Thanked 1 Time in 1 Post

    Default Re: Help please!

    Quote Originally Posted by jeeba View Post
    It is listed as a valid method over here. Is my implementation wrong?
    I misspoke.

    What type of object is toCharArray() a method for?

    What type of object have you called toCharArray on? Is it a String? Is it an array of Strings? Is it something else altogether?

  5. The Following User Says Thank You to mjpam For This Useful Post:

    jeeba (September 22nd, 2010)

  6. #5
    Moderators helloworld922's Avatar
    Join Date
    Jun 2009
    Posts
    2,896
    Thanks
    23
    Thanked 619 Times in 561 Posts
    Blog Entries
    18

    Default Re: Help please!

    toCharArray() is a valid method of a String object, not a String array object (a very important distinction).

  7. The Following User Says Thank You to helloworld922 For This Useful Post:

    jeeba (September 22nd, 2010)

  8. #6
    Junior Member
    Join Date
    Sep 2010
    Posts
    3
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: Help please!

    Oh gosh! I feel so dumb now

    Thank you for your time though!