This week's book giveaway is in the OCP forum.
We're giving away four copies of OCP Java SE 8 Programmer II Exam Study Guide and have Kathy Sierra, Bert Bates, & Elizabeth Robson on-line!
See this thread for details.
Win a copy of OCP Java SE 8 Programmer II Exam Study Guide this week in the OCP forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

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

 
Ranch Hand
Posts: 534
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?

 
Author and ninkuma
Marshal
Posts: 66535
160
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 ==
 
Sheriff
Posts: 11745
191
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: 11745
191
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: 534
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
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!