Win a copy of Learning OpenStack Networking: Build a solid foundation in virtual networking technologies for OpenStack-based clouds this week in the Cloud/Virtualization forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

illegal start of expression line 31  RSS feed

 
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!



 
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.
 
Bartender
Posts: 3320
86
  • 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.
 
Marshal
Posts: 60127
188
  • 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 {}.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!