Results 1 to 4 of 4
  1. #1
    Join Date
    Mar 2011
    Posts
    93
    Rep Power
    0

    Default illegal start of expression prob

    Hello. Another in a long list of stupid questions I have. My apologies.

    This program is supposed to print out all the odd elements in an array of ints.

    But I get an illegal start of expression errors referencing line 13. I don't think I have a probelm with defining a method inside another method, nor is there a problem with the curly braces.

    Can someone point out my error. Thanks in advance.

    Java Code:
    import java.util.Arrays;
    
    public class AppI {
    
        public static void main(String[] args) {
            
            int[] iArray = { 23, 6, 47, 35, 2, 14 };
            
            //Arrays.sort(iArray);
            //System.out.print(iArray[5]);
            
            for (int i = 0; i < iArray.length; i++) {
                if ( (iArray[i]%2) !==0 ) {
                    System.out.println(iArray[i]);
                }
            }      
        }
    }

  2. #2
    JavaAdviser is offline Member
    Join Date
    Sep 2012
    Posts
    26
    Rep Power
    0

    Default Re: illegal start of expression prob

    The unequal operator is not !== but !=

  3. #3
    Join Date
    Mar 2011
    Posts
    93
    Rep Power
    0

    Default Re: illegal start of expression prob

    Yep, that fixes it!! Thank you!!

    Time to go read about = and == operators.

  4. #4
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,798
    Rep Power
    7

    Default Re: illegal start of expression prob

    This issue could be simplified by increasing the loop variable by 2 instead of 1. Then you can get rid of the if statement.

Similar Threads

  1. Illegal start of expression
    By eddyk6 in forum New To Java
    Replies: 4
    Last Post: 01-27-2012, 08:51 AM
  2. Illegal start of expression
    By lodaSchitt in forum New To Java
    Replies: 2
    Last Post: 04-28-2011, 11:04 PM
  3. Need help with illegal start of expression
    By WhopperMan in forum New To Java
    Replies: 4
    Last Post: 10-10-2010, 03:58 AM
  4. Illegal Start of Expression
    By vince425 in forum New To Java
    Replies: 3
    Last Post: 10-18-2008, 08:41 AM
  5. illegal start of expression
    By razmyasdfg in forum CLDC and MIDP
    Replies: 2
    Last Post: 07-27-2008, 11:44 PM

Posting Permissions

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