Page 1 of 2 12 LastLast
Results 1 to 20 of 21
  1. #1
    MAJ
    MAJ is offline Member
    Join Date
    Jul 2014
    Posts
    17
    Rep Power
    0

    Default illegal start of expression

    Explain to me how that's possible

    import java.util.*;
    public class Stars
    {
    public static void main(String[] args)
    {
    line (13);
    line (7);
    line (35);
    System.out.println();
    box(10,3);
    box(5, 4);
    box(20,7);
    }
    public static void line(int count)
    {
    for (int i = 1; i <= count; i++)
    {
    System.out.println();
    }
    public static void box(int width,int height)
    {
    line(width);
    for (int line = 1; line<= height - 2; line++)
    {
    System.out.print("*");
    for (int space = 1; space <= width - 2; space++)
    {
    System.out.print(" ");
    }
    System.out.println("*");
    }

  2. #2
    Tolls is online now Moderator
    Join Date
    Apr 2009
    Posts
    12,006
    Rep Power
    20

    Default Re: illegal start of expression

    This is the third time now I have had to ask you to post your code in [ code] tags [ /code].

    Are you simply not listening?
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  3. #3
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,518
    Blog Entries
    7
    Rep Power
    20

    Default Re: illegal start of expression

    @MAJ: please properly indent your code and use [code] ... [/code] tags around your code when you post it; this is inreadably as it is now.

    kind regards,

    Jos

    edit: the slow old sod tries to post something again ...
    cenosillicaphobia: the fear for an empty beer glass

  4. #4
    gimbal2 is online now Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    3,992
    Rep Power
    5

    Default Re: illegal start of expression

    Quote Originally Posted by JosAH View Post
    edit: the slow old sod tries to post something again ...
    This is like that story: the tortoise and the turtle.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  5. #5
    MAJ
    MAJ is offline Member
    Join Date
    Jul 2014
    Posts
    17
    Rep Power
    0

    Default Re: illegal start of expression

    Quote Originally Posted by Tolls View Post
    This is the third time now I have had to ask you to post your code in [ code] tags [ /code].

    Are you simply not listening?
    Actually its the second time. I'm sorry but I don't understand how you want me to post my code. I'm new here.

  6. #6
    MAJ
    MAJ is offline Member
    Join Date
    Jul 2014
    Posts
    17
    Rep Power
    0

    Default Re: illegal start of expression

    [QUOTE=JosAH;392049]@MAJ: please properly indent your code and use [code] ... [/code] tags around your code when you post it; this is inreadably as it is now.

    kind regards,

    Jos

    I'm pretty sure there is no such thing as "inreadably". I will try to get into the habit of indenting my code.

  7. #7
    Tolls is online now Moderator
    Join Date
    Apr 2009
    Posts
    12,006
    Rep Power
    20

    Default Re: illegal start of expression

    And [code] tags.
    Indenting code without using code tags when you post it here is no use at all.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  8. #8
    AlexGraal is offline Señor Member
    Join Date
    Jan 2014
    Posts
    184
    Rep Power
    0

    Default Re: illegal start of expression

    As Tolls just posted on your other thread...what is the error you are getting? What is it? I'm not going to go stick it into an IDE to see where it is. You have seen the error, now post it to here if you want any help.

  9. #9
    MAJ
    MAJ is offline Member
    Join Date
    Jul 2014
    Posts
    17
    Rep Power
    0

    Default Re: illegal start of expression

    Quote Originally Posted by AlexGraal View Post
    As Tolls just posted on your other thread...what is the error you are getting? What is it? I'm not going to go stick it into an IDE to see where it is. You have seen the error, now post it to here if you want any help.

    Stars.java:20: error: illegal start of expression
    public static void box(int width,int height)
    ^
    Stars.java:20: error: illegal start of expression
    public static void box(int width,int height)
    ^
    Stars.java:20: error: ';' expected
    public static void box(int width,int height)
    ^
    Stars.java:20: error: '.class' expected
    public static void box(int width,int height)
    ^
    Stars.java:20: error: ';' expected
    public static void box(int width,int height)
    ^
    Stars.java:20: error: ';' expected
    public static void box(int width,int height)
    ^
    Stars.java:31: error: reached end of file while parsing
    }
    ^
    7 errors
    That was a pain in the neck. It took me less than 1 minute to find out the errors and put them on here.

  10. #10
    MAJ
    MAJ is offline Member
    Join Date
    Jul 2014
    Posts
    17
    Rep Power
    0

    Default Re: illegal start of expression

    Quote Originally Posted by Tolls View Post
    And [code] tags.
    Indenting code without using code tags when you post it here is no use at all.
    I can't get into the habit of doing something that I wasn't taught.

  11. #11
    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

    Post #2 told you exactly what you need to do to add code tags.

    Your problem should be obvious if your code was properly indented. Where is your box method?

  12. #12
    MAJ
    MAJ is offline Member
    Join Date
    Jul 2014
    Posts
    17
    Rep Power
    0

    Default Re: illegal start of expression

    You mean like this?
    Java Code:
      
       import java.util.*;
       public class Stars
           {
       public static void main(String[] args)
            {
              line (13);
              line (7);
              line (35);
             System.out.println();
             box(10,3);
             box(5, 4);
             box(20,7);
               }
           public static void line(int count)
               {
               for (int i = 1; i <= count; i++)
               {
                System.out.println();
                }
           public static void box(int width,int height)
               {
                 line(width);
                for (int line = 1; line<= height - 2; line++)
               {
                 System.out.print("*");
                 for (int space = 1; space <= width - 2; space++)
               {
                  System.out.print(" ");
               }
                 System.out.println("*");
               }
    I don't think my problem would be obvious if I indented. Isn't this my box method?:
    box(10,3);
    box(5, 4);
    box(20,7);
    Last edited by MAJ; 07-31-2014 at 05:01 AM.

  13. #13
    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

    Quote Originally Posted by MAJ View Post
    I don't think my problem would be obvious if I indented. Isn't this my box method?:
    Yes it would.
    On which line does the line method start?
    On which line does the line method end?
    On which line does the box method start?

  14. #14
    MAJ
    MAJ is offline Member
    Join Date
    Jul 2014
    Posts
    17
    Rep Power
    0

    Default Re: illegal start of expression

    The line method starts at 6 and ends at 8. The box method starts at 10 and ends at 13.

  15. #15
    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

    Wrong.

    You are referring to the method calls. I am asking about the actual method implementations. I'll give you a head start: the line method begins on line 14.

  16. #16
    MAJ
    MAJ is offline Member
    Join Date
    Jul 2014
    Posts
    17
    Rep Power
    0

    Default Re: illegal start of expression

    Ok, I'm guessing it ends at 22.

  17. #17
    Tolls is online now Moderator
    Join Date
    Apr 2009
    Posts
    12,006
    Rep Power
    20

    Default Re: illegal start of expression

    Quote Originally Posted by MAJ View Post
    I don't think my problem would be obvious if I indented.
    Then you would be wrong.
    This is what your code looks like when each level is correctly indented with the brackets matching up as best as possible.

    You have methods buried in methods.
    Or, simply, you have missing brackets...which would have been clear had you formatted your code correctly.
    It's one of the reasons for formatting code correctly, to catch mistakes like this.
    The other is so that it is easier to read.

    Java Code:
      
    import java.util.*;
    public class Stars
    {
        public static void main(String[] args)
        {
            line (13);
            line (7);
            line (35);
            System.out.println();
            box(10,3);
            box(5, 4);
            box(20,7);
        }
        public static void line(int count)
        {
            for (int i = 1; i <= count; i++)
            {
                System.out.println();
            }
           public static void box(int width,int height)
           {
               line(width);
               for (int line = 1; line<= height - 2; line++)
               {
                   System.out.print("*");
                   for (int space = 1; space <= width - 2; space++)
                   {
                       System.out.print(" ");
                   }
                   System.out.println("*");
               }
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  18. #18
    gimbal2 is online now Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    3,992
    Rep Power
    5

    Default Re: illegal start of expression

    Gee Tolls, what is that huge gaping incredibly easy to see empty space at the bottom there? Where did that come from all so suddenly?

    Hmmmmmmm. Mysterious.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  19. #19
    AlexGraal is offline Señor Member
    Join Date
    Jan 2014
    Posts
    184
    Rep Power
    0

    Default Re: illegal start of expression

    Well that was a pain in the neck. It took me less than 1 minute to find the error. In your code. Once it was actually formatted correctly. By somebody else.

    And I won't post it since you should be able to see it now :)

    A hint since you've been slow to pick up "things that haven't been taught" to you: methodception.

  20. #20
    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

    Quote Originally Posted by MAJ View Post
    Ok, I'm guessing it ends at 22.
    That is yet another method call. Are you trolling or do you simply have no idea what you are doing?

Page 1 of 2 12 LastLast

Similar Threads

  1. illegal start of an expression!!
    By gbonecapone in forum New To Java
    Replies: 3
    Last Post: 06-06-2013, 09:08 PM
  2. Illegal start of expression
    By lodaSchitt in forum New To Java
    Replies: 2
    Last Post: 04-28-2011, 10:04 PM
  3. Illegal Start of Expression
    By Tyre in forum New To Java
    Replies: 20
    Last Post: 04-15-2011, 02:50 PM
  4. Need help with illegal start of expression
    By WhopperMan in forum New To Java
    Replies: 4
    Last Post: 10-10-2010, 02:58 AM
  5. Illegal Start of an Expression
    By ddatta8 in forum New To Java
    Replies: 3
    Last Post: 12-20-2008, 08:40 PM

Tags for this Thread

Posting Permissions

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