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: Illegal start of expression

  1. #1
    Junior Member
    Join Date
    Feb 2013
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Illegal start of expression

    trying to take char input and display whether a vowel

    i get error saying that enum has illegal start of expression and that it must not be local

    boolean.java:6: illegal start of expression
    public enum vowels
    ^

    boolean.java:6:enum types must not be local
    public enum vowels
    ^

    im really new and i dont know what ive done

    public class Boolean {
     
    	public static void main (String[] args) {
     
    		public enum vowels {
    		A('a'),E('e'),I('i'),O('o'),U('u');
    		}
    		char letterinput;
    	        boolean isVowel;
    		System.out.print("Enter a letter: ");
    		int c = System.in.read();
    		letterinput = (char)c;
    		while(System.in.available() > 0) { 
    		System.in.read(); 
    		}
    		if (letterinput == vowels) {
    		isVowel = true;
    		System.out.println(letterinput + "is a vowel");
    		} else {
    		isVowel = false;
    		System.out.println(letterinput + "is not a vowel");
    		}
    	}
    }


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    21,775
    Thanks
    54
    Thanked 2,340 Times in 2,311 Posts

    Default Re: Illegal start of expression

    i get error
    Please copy the full text of the error messages and post them here.

    Try moving the enum outside of the method.
    Also see the tutorial: http://docs.oracle.com/javase/tutori...vaOO/enum.html

    BTW Boolean is the name of a java SE class. It'd be less confusing if you used your own name for your class.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Feb 2013
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Illegal start of expression

    I have seen the tutorial and I`m pretty sure I have copied the syntax to the letter unless you actually have to have each constant on a new line, also upon moving the enum outside the method the compiler then fails to recognise the vowels identifier

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    21,775
    Thanks
    54
    Thanked 2,340 Times in 2,311 Posts

    Default Re: Illegal start of expression

    Your usage of vowels needs some more stuff: add on one of the enum names like A: vowels.A

    Post the full text of any error messages. I don't remember "fails to recognize" as a compiler error.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Illegal start of expression!
    By NoobOfTheMonth in forum What's Wrong With My Code?
    Replies: 9
    Last Post: February 11th, 2013, 09:53 PM
  2. Help With illegal start of expression
    By inshal in forum What's Wrong With My Code?
    Replies: 6
    Last Post: February 9th, 2013, 01:20 PM
  3. need help with illegal start of expression
    By inshal in forum What's Wrong With My Code?
    Replies: 0
    Last Post: February 9th, 2013, 11:25 AM
  4. Help With illegal start of expression
    By RaceRed in forum What's Wrong With My Code?
    Replies: 4
    Last Post: February 7th, 2013, 09:02 PM
  5. illegal start of expression error!!!!
    By aks.1393 in forum What's Wrong With My Code?
    Replies: 4
    Last Post: January 14th, 2011, 08:47 AM