• Post Reply Bookmark Topic Watch Topic
  • New Topic

Using switch statement inside if statement  RSS feed

 
Si Mon
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So I want to make a simple Java that ask the user to pick a powers and it has two options.
If the user picks magic then execute the first if statement then ask the user again which type of magic the user wants.
I can't make it work it keeps printing the else statement. Why is that?
I'm not getting error message using eclipse so i don't know how to fix it.


 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16060
88
Android IntelliJ IDE Java Scala Spring
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In Java, you should not compare strings using ==. The == operator does not check if the two strings on the left and right side have the same content - it checks if the expression on the left and right refer to the exact same object. When you have two separate String objects with the same content, == will return false. Use .equals() instead to compare strings.



 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!