• Post Reply Bookmark Topic Watch Topic
  • New Topic

If statements  RSS feed

 
Ryan O'Neill
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This code won't execute due to this:2 errors found:
File: /Users/ryoneill/Desktop/PA4ONeill.java [line: 77]
Error: /Users/ryoneill/Desktop/PA4ONeill.java:77: ';' expected
File: /Users/ryoneill/Desktop/PA4ONeill.java [line: 92]
Error: /Users/ryoneill/Desktop/PA4ONeill.java:92: ';' expected
I have tried for about 8 hours to get this to run but can't.
Any help would be much appreciated.

 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The line numbers here don't seem to to be the same as in your error messages, but at a quick glance I see that a) you're using the keyword "If" which Java does not have (it is case-sensitive), b) same for "elseif" (need to use a space), and c) the "If" block does not have a closing curly brace.
 
Ryan O'Neill
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks so much, now it says this:
1 error found:
File: /Users/ryoneill/Desktop/PA4ONeill.java [line: 121]
Error: /Users/ryoneill/Desktop/PA4ONeill.java:121: cannot find symbol
symbol : method elseif(boolean)
location: class PA4ONeill

[code=java][/code
elseif((option.equals("c")&& option.equals("C")));
 
Paweł Baczyński
Bartender
Posts: 2083
44
Firefox Browser IntelliJ IDE Java Linux Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is no elseif keyword in Java. It should be else if.

Also. Even if you write else if correctly, your code won't do what you expect.

Notice semicolon at the end of if statement? It is what your if will do if its expression evaluates to true. And ; means empty statement. Nothing.
And next, the block marked by curly braces will be executed. Always.
 
Matthew Brown
Bartender
Posts: 4568
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, as Ulf said, there is no "elseif" codeword. It's "else if".
 
Campbell Ritchie
Marshal
Posts: 56540
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Since everybody else has told you it's else if not elseif (some languages do use elseif), I'll tell you it's else if not elseif


I shall say something new, too:-
Welcome to the Ranch
 
Paweł Baczyński
Bartender
Posts: 2083
44
Firefox Browser IntelliJ IDE Java Linux Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell Ritchie wrote:Since everybody else has told you it's else if not elseif (some languages do use elseif)

And some use elsif and other elif
 
Campbell Ritchie
Marshal
Posts: 56540
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
Ryan O'Neill
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the help I really appreciate it.
Any tips for beginners in java?
A tutorial? blog? book? article?
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66306
152
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Head First Java is the odds-on favorite.
 
Scott Winterbourne
Ranch Hand
Posts: 116
2
Eclipse IDE Java PHP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Indeed, Head First Java in my opinion was a great starting place for me.

Be careful of digital PDF versions of books as they could be scans and some of the characters might not have been scanned or converted correctly. I have come across this issue several times. A legitimate copy of the latest edition will greatly reduce these typos and mistakes.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!