Results 1 to 20 of 21
Thread: illegal start of expression
- 07-30-2014, 10:59 AM #1
Member
- Join Date
- Jul 2014
- Posts
- 17
- Rep Power
- 0
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("*");
}
- 07-30-2014, 11:44 AM #2
Moderator
- Join Date
- Apr 2009
- Posts
- 13,541
- Rep Power
- 27
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 **
- 07-30-2014, 11:45 AM #3
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 14,422
- Blog Entries
- 7
- Rep Power
- 29
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 ...Build a wall around Donald Trump; I'll pay for it.
- 07-30-2014, 11:47 AM #4
Just a guy
- Join Date
- Jun 2013
- Location
- Netherlands
- Posts
- 5,114
- Rep Power
- 13
- 07-30-2014, 05:44 PM #5
Member
- Join Date
- Jul 2014
- Posts
- 17
- Rep Power
- 0
- 07-30-2014, 05:49 PM #6
Member
- Join Date
- Jul 2014
- Posts
- 17
- Rep Power
- 0
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.
- 07-30-2014, 05:58 PM #7
Moderator
- Join Date
- Apr 2009
- Posts
- 13,541
- Rep Power
- 27
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 **
- 07-30-2014, 09:12 PM #8
Señor Member
- Join Date
- Jan 2014
- Posts
- 184
- Rep Power
- 0
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.
- 07-30-2014, 09:25 PM #9
Member
- Join Date
- Jul 2014
- Posts
- 17
- Rep Power
- 0
Re: illegal start of expression
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.
- 07-30-2014, 09:35 PM #10
Member
- Join Date
- Jul 2014
- Posts
- 17
- Rep Power
- 0
- 07-31-2014, 05:09 AM #11
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?
- 07-31-2014, 05:57 AM #12
Member
- Join Date
- Jul 2014
- Posts
- 17
- Rep Power
- 0
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("*"); }
box(10,3);
box(5, 4);
box(20,7);Last edited by MAJ; 07-31-2014 at 06:01 AM.
- 07-31-2014, 06:01 AM #13
- 07-31-2014, 06:57 AM #14
Member
- Join Date
- Jul 2014
- Posts
- 17
- Rep Power
- 0
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.
- 07-31-2014, 07:07 AM #15
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.
- 07-31-2014, 07:22 AM #16
Member
- Join Date
- Jul 2014
- Posts
- 17
- Rep Power
- 0
Re: illegal start of expression
Ok, I'm guessing it ends at 22.
- 07-31-2014, 10:39 AM #17
Moderator
- Join Date
- Apr 2009
- Posts
- 13,541
- Rep Power
- 27
Re: illegal start of expression
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 **
- 07-31-2014, 11:43 AM #18
Just a guy
- Join Date
- Jun 2013
- Location
- Netherlands
- Posts
- 5,114
- Rep Power
- 13
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
- 07-31-2014, 11:19 PM #19
Señor Member
- Join Date
- Jan 2014
- Posts
- 184
- Rep Power
- 0
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.
- 08-01-2014, 03:46 AM #20
Similar Threads
-
illegal start of an expression!!
By gbonecapone in forum New To JavaReplies: 3Last Post: 06-06-2013, 10:08 PM -
Illegal start of expression
By lodaSchitt in forum New To JavaReplies: 2Last Post: 04-28-2011, 11:04 PM -
Illegal Start of Expression
By Tyre in forum New To JavaReplies: 20Last Post: 04-15-2011, 03:50 PM -
Need help with illegal start of expression
By WhopperMan in forum New To JavaReplies: 4Last Post: 10-10-2010, 03:58 AM -
Illegal Start of an Expression
By ddatta8 in forum New To JavaReplies: 3Last Post: 12-20-2008, 09:40 PM
Bookmarks