• Post Reply Bookmark Topic Watch Topic
  • New Topic

equals  RSS feed

 
ekte spiriopoulos
Ranch Hand
Posts: 217
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i want to write a string : word ball

 
Campbell Ritchie
Marshal
Posts: 56570
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I cannot see any problem with that code. Maybe it would be good to write this sort of thing before it:-
System.out.print("Please enter type: \"ball\" \"bat\" or \"stumps\": ");
 
Campbell Ritchie
Marshal
Posts: 56570
172
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you want to move the entry into the loop, you will have to learn some strange syntax. We do not usually show complete solutions to beginners, but this is so strange you would never work it out for yourselfYou need () round the = sign because it has low precedence, so as to make sure that reading takes place before the equals test. You can of course turn it round:-
while ("ball".equalsIgnoreCase((input = UserInput.getString()))
I do not know whether it is necessary to write "ball" first; if you use a Scanner I believe it isn't because Scanners never return null. You can also try a do loop:-I trust you know the difference between a while loop and a do loop?
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!