This week's book giveaway is in the JavaScript forum.
We're giving away four copies of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js and have Paul Jensen on-line!
See this thread for details.
Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

IF...ELSE  RSS feed

 
Thomas Markl
Ranch Hand
Posts: 192
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

C:\Java\EigeneJavaProgramme>java ZombieStomp
Killer Of Giants
Symphony of Destruction
If str = „markl“ then (str instanceof String) is true
AND (str instanceof Object) is true.
Why doesn’t it print:
Killer Of Giants
I Shot the Sheriff
Symphony of Destruction
 
Marilyn de Queiroz
Sheriff
Posts: 9080
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


If str = „markl“ then (str instanceof String) is true
AND (str instanceof Object) is true.
Why doesn’t it print:


Killer Of Giants
I Shot the Sheriff
Symphony of Destruction


because of the 'else'. Read --

if str is an instance of string => print Killer Of Giants

or else if string is not an instance of string but is an instance of Object => print I Shot the Sheriff

then always print Symphony of Destruction
 
James Chegwidden
Author
Ranch Hand
Posts: 201
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is there any particular reason you added the final keyword in the main method header?
 
Younes Essouabni
Ranch Hand
Posts: 479
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If your first condition evaluate to true, the "else" won't be evaluated.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!