• Post Reply Bookmark Topic Watch Topic
  • New Topic

Java output,why won't it output the correct statement?  RSS feed

 
Adam Chalkley
Ranch Hand
Posts: 518
4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi for some reason my program will not print the line "Square" to the terminal when the condition is met I don't know whats going on,I'm not to sure about the java.io package but our lecturer has told us to ignore that for now and just focus on the code we know anyway here is my code how can I fix this simple mistake and get the output to say "square" when line1 and line2 are equal?

 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66304
152
IntelliJ IDE Java jQuery Mac Mac OS X
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What's the correct way to compare string values?

Hint: it isn't ==
 
Junilu Lacar
Sheriff
Posts: 11476
180
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear's point is valid and you should consider it but consider this as well: why are you trying to compare the string inputs when you have already converted them to the proper type that you want? Are lengths strings or numbers?
 
Junilu Lacar
Sheriff
Posts: 11476
180
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also the second if, the one after else is redundant: just the else is necessary and it will get executed when the first if condition is not met.
 
Adam Chalkley
Ranch Hand
Posts: 518
4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Junilu Lacar wrote:Also the second if, the one after else is redundant: just the else is necessary and it will get executed when the first if condition is not met.


sorry about the late reply,thanks man much appreciated :P:P
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!