• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Conditionals

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 17644
300
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Likes 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 2236
63
IntelliJ IDE Firefox Browser Spring Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Also, don't write

Instead write
 
Marshal
Posts: 79040
375
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic