CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Jan 2013
    Posts
    2

    [RESOLVED] Using length() method.

    I am just starting to learn java, I am playing with using strings. I am trying to get a code to select a random word and print it.

    Code:
    public class test2 {
    
        public static void main(String[] args) {
        String[] wordListOne={"Dave","Nick","Paul","Mark","John","Bill","Gil"};
        int length1 = wordListOne.length();
        int rand1 = (int) (Math.random() * length1);
        String finalPhrase = wordListOne[rand1];
        System.out.println(finalPhrase);
      }
    }
    length() is not working and I am getting the error, "can not find symbol - method length()"

  2. #2
    Join Date
    Jan 2013
    Posts
    2

    Re: Using length() method.

    Fixed it myself. Got rid of round brackets and that was the key.

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured