Two Laptop Bag*
The moose likes Beginning Java and the fly likes syntax error on token Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "syntax error on token "else"" Watch "syntax error on token "else"" New topic
Author

syntax error on token "else"

Abel Gonza
Greenhorn

Joined: Sep 05, 2011
Posts: 3
I can't seem to figure out why this is happening. Any tips at all will be very appreciated.
syntax error on token "else", delete this token.



I'll post all the code if requested.




Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19654
    
  18

Welcome to the Ranch!

After the word "else" there shouldn't be any guard anymore - just the { or statement. That statement can be another "if", which is what I think you want:
Also, are you aware of method equalsIgnoreCase? You can use that to shorten your code:


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Abel Gonza
Greenhorn

Joined: Sep 05, 2011
Posts: 3
Rob Spoor wrote:Welcome to the Ranch!

After the word "else" there shouldn't be any guard anymore - just the { or statement. That statement can be another "if", which is what I think you want:
Also, are you aware of method equalsIgnoreCase? You can use that to shorten your code:



What do you mean guard?
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11161
    
  16

and else statement doesn't have a condition on it. The idea is that on the IF and IF-ELSE lines, you have handled most conditions. the ELSE is for everything that wasn't caught by the previous statements. the general flow should be:



There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Abel Gonza
Greenhorn

Joined: Sep 05, 2011
Posts: 3
got it thanks
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19654
    
  18

Abel Gonza wrote:What do you mean guard?

Sorry, that's the term I once learned for it. I guess in Java it's more often called the condition.
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14074
    
  16

I'm surprised nobody noticed this yet: you have a ; after your if-statements that should not be there.

This must be:


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19654
    
  18

Didn't even notice these.
 
Consider Paul's rocket mass heater.
 
subject: syntax error on token "else"
 
Similar Threads
Rock Paper Scissors
please help! simple java program of rock paper scissors
Which is your favorite Star Wars Episode?
Refactoring Exercise
i need help letting a user input anything all upercase, lowercase, or both.