• Post Reply Bookmark Topic Watch Topic
  • New Topic

illegal start of expression line 31  RSS feed

 
Jessica Benady
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Would anyone be able to find errors in this code? It says that there is an illegal start of expression at line 31, but I suspect that there's probably something wrong in the way I wrote the code somewhere else, I simply can't find my mistake.



Thanks!



 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, and welcome to the Ranch!

When posting code, please UseCodeTags(←click) so that it will be readable. I've added them to your post here.

As for your question, that error usually comes when have an extra close brace, or write statements directly inside a class body rather than inside a method, constructor, or initializer block. The line numbers in the code posted here may not match those in your editor, such as if package or import statements or opening comments are omitted, so please indicate which line in the code here corresponds to the line 31 where you're getting the error in your original code.
 
Tony Docherty
Bartender
Posts: 3271
82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Looks like you could be missing a closing brace after this line:

And you probably have an extra one at the end of the file.
 
Jessica Benady
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Thanks for your help, you were right I was missing a brace! Now I've added to the program and am once again getting errors, I'm sorry if these are really obvious mistakes, but I'm a beginner in java!
The errors are around line 21 & 22, where I have a nested loop and am asking the program to print digit and per[i] to the screen, the error says I'm missing a ")", but I don't think that's it, can anyone see my mistake?

 
Jessica Benady
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ahem, pardon the error is line 28!!
 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


you should be able to figure out what's wrong with this line just by looking at it very closely. You did the right thing in part of the line, but not the other part, so it seems you know the right way to do it.



Four problems here:

1) It should be a backslash \n, not the forward slash that you wrote.

2) It needs to be in quotes, either single for a char or double for a String.

3) You should use System.getProperty("line.separator") rather than hardcoding a platform-specific line terminator.

4) If you use println() instead of print() in the previous line, it will include a line terminator for you.
 
Campbell Ritchie
Marshal
Posts: 56593
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am afraid your code is difficult to read because of the long lines.
The whole idea behind indentation is that it enables you to count {}. You will find some suggestions about indentation here and here. Yes, I am telling you to write code backwards, because that reduces the risk of unbalanced {}.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!