Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
  • 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:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • paul wheaton
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Tim Holloway
  • Carey Brown
  • salvin francis

Conditionals

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey guys, Im having some trouble with this bit of code. Idk why but the last else in the String is marked as a syntax error. I've tried changing as much as possible but it doesn't seem to get fixed (btw ik its probably something really stupid but I recently started trying to code and can't figure this out for the life of me)

 
Sheriff
Posts: 13675
226
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch!

Errors with else clauses are usually caused by semicolons that should not be there. Look for the stray semicolon between if and else. There shouldn't be one.
 
Bartender
Posts: 2220
47
IntelliJ IDE Firefox Browser Spring Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also, don't write

Instead write
 
Marshal
Posts: 65365
248
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch again.

Thank you for using code tags but you didn't quite get them right. [code=java] goes before the code and [/code] after it. Since you are new I have corrected it; doesn't it look better
Please start methodNames with lowerCaseLetters. Not PlacaImpar(), but placaImpar() please.
You have doubtless been told that chars are letters, but they aren't. They are numbers which are displayed as letters corresponding to their ASCII/Unicode values. If they are numbers, you can do arithmetic with them, but I recommend you keep the arithmetic very simple. There is no need to use parseInt() if you can do this:-If you look up an ASCII table, or this Unicode page, you will find the digits have code numbers in order 0 1 2 3.... You can do the same with letters, but it only works for English writing, not French or Spanish because letters like é and ñ are in a different order.
I challenge you to find out why i % 2 == 0 will work and i % 2 == 1 sometimes won't. Actually, I would write the placaImpar() method like this:-Do you want those methods to be used by code outside your current class? If not, give them private access.
 
Put the moon back where you found it! We need it for tides and poetry and stuff. Like this tiny ad:
create, convert, edit or print DOC and DOCX in Java
https://products.aspose.com/words/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!