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 4 of 4

Thread: ']' expected

  1. #1
    Junior Member
    Join Date
    Jul 2012
    Location
    Netherlands
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question ']' expected

    I have the following code in my source: (starting from the top)
    import java.util.*;
     
    class PronouncablePasswordGenerator
    {
        public static void main(String[] arguments) {
    final char[] Vowels = new char['a', 'e', 'i', 'o', 'u', 'y'];

    And javac gives this output:
    Z:\dev\Java\PPG\ppg.java:7: ']' expected
    final char[] Vowels = new char['a', 'e', 'i', 'o', 'u', 'y'];
                                      ^

    Obviously it does not compile, I have waay too many errors in my code, but this error is one that puzzles me most, since:
    - there IS a ] there.
    - and what does the ^ below the 's' of Vowels mean? does it expect a ']' there? (I know that on this webpage shows the '^' below the comma of the 'a', but in the output text-file I got from javac, it is where I said it is)

    Thanks for your help! I'm using this project as a useful device for learning Java. This program (when finished) should be useful in years to come.


  2. #2
    Member
    Join Date
    Jul 2012
    Posts
    119
    Thanks
    0
    Thanked 19 Times in 19 Posts

    Default Re: ']' expected

    Quote Originally Posted by MagicMojoSoftware View Post
    I have the following code in my source: (starting from the top)
    import java.util.*;
     
    class PronouncablePasswordGenerator
    {
        public static void main(String[] arguments) {
    final char[] Vowels = new char['a', 'e', 'i', 'o', 'u', 'y'];

    And javac gives this output:
    Z:\dev\Java\PPG\ppg.java:7: ']' expected
    final char[] Vowels = new char['a', 'e', 'i', 'o', 'u', 'y'];
                                      ^

    Obviously it does not compile, I have waay too many errors in my code, but this error is one that puzzles me most, since:
    - there IS a ] there.
    - and what does the ^ below the 's' of Vowels mean? does it expect a ']' there? (I know that on this webpage shows the '^' below the comma of the 'a', but in the output text-file I got from javac, it is where I said it is)

    Thanks for your help! I'm using this project as a useful device for learning Java. This program (when finished) should be useful in years to come.
    You made a syntax mistake. It should be
    char[] Vowels = {'a', 'e', 'i', 'o', 'u', 'y'};

  3. #3
    Junior Member
    Join Date
    Jul 2012
    Location
    Netherlands
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: ']' expected

    So it's accolades instead of square brackets, huh? You live and learn.
    Is it always accolades instead of square brackets? I would have never expected that, guess I'm too stuck in my C++-ways. I already seemed to be that because I thought Java would be easy to learn given my C++ background. Maybe it's just that my C++-experience is from too long ago to be useful.

    Anyway, I fixed that and updated the rest of the arrays too. (I have 3: vowels, consonants and non-alpha-numeric symbols)

    But now I get this error:
    Z:\dev\java\ppg\ppg.java:10: error: '.class' expected
    final char[] Consonants = char{'b', 'c', 'd', 'f', 'g', 'h', 'j', 'l', 'm', 'n', 'p', 'q', 'r', 's', 't', 'v', 'w', 'x', 'z'};

    Guess that's related to the bit about the {} in place of where I thought it would be [].
    Once again, my code-snippet including line 10

    import java.util.*;
     
    class PronouncablePasswordGenerator
    {
        public static void main(String[] arguments) {
    // Pronouncable password generator
    //final char[] Vowels = new char['a', 'e', 'i', 'o', 'u', 'y'];
    final char[] Vowels = {'a', 'e', 'i', 'o', 'u', 'y'};
    //final char[] Consonants = new char['b', 'c', 'd', 'f', 'g', 'h', 'j', 'l', 'm', 'n', 'p', 'q', 'r', 's', 't', 'v', 'w', 'x', 'z'];
    final char[] Consonants = char{'b', 'c', 'd', 'f', 'g', 'h', 'j', 'l', 'm', 'n', 'p', 'q', 'r', 's', 't', 'v', 'w', 'x', 'z'};

  4. #4
    Member
    Join Date
    Jul 2012
    Posts
    119
    Thanks
    0
    Thanked 19 Times in 19 Posts

    Default Re: ']' expected

    Oh MagicMojoSoftware,
    my background is not only c++, c but also Pascal, PLI, AssemblerBack to your "complaint". You made again an C mistake:
    WRONG is the red marking at: final char[] Consonants = char{'b', 'c', 'd', 'f', 'g', 'h', 'j', 'l', 'm', 'n', 'p', 'q', 'r', 's', 't', 'v', 'w', 'x', 'z'};
    CORRECT is final char[] Consonants = {'b', 'c', 'd', 'f', 'g', 'h', 'j', 'l', 'm', 'n', 'p', 'q', 'r', 's', 't', 'v', 'w', 'x', 'z'};

Similar Threads

  1. '{' expected error please help
    By erdy_rezki in forum What's Wrong With My Code?
    Replies: 8
    Last Post: April 9th, 2012, 10:01 AM
  2. [SOLVED] Output isn't as expected.
    By woodcutterni in forum What's Wrong With My Code?
    Replies: 2
    Last Post: February 12th, 2011, 11:55 AM
  3. Identifier expected
    By Sphinx in forum What's Wrong With My Code?
    Replies: 5
    Last Post: November 30th, 2010, 02:50 PM
  4. <identifier> expected
    By Trunk Monkeey in forum What's Wrong With My Code?
    Replies: 1
    Last Post: November 21st, 2010, 09:33 PM
  5. ';' expected?
    By noobish in forum What's Wrong With My Code?
    Replies: 4
    Last Post: November 21st, 2009, 11:55 AM

Tags for this Thread