This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

if and if else code problem

 
lakmal padmakumara
Ranch Hand
Posts: 47
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


In this code if I input 'N' or 'n' the register method get called.But if I input 'l' or 'L' the login method doesnt get called.I swapped
"if "and "if else" code parts and tried again.That time the Login method did get called ,and register method wasn't activated.So the problem is with the if else code parts .Not with those methods code parts.Please Someone help me to pint out this error.It may bea very simple one.But cannot figure out it at the moment.
 
Priety Sharma
Ranch Hand
Posts: 156
Android Eclipse IDE
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi lakmal,

Why dont you try storing the output of input.next().charAt(0) and then using that variable in the comparinson instead of calling input.next().charAt(0) everytime.

The repeated call to input.next().charAt(0) could be the problem.
I am guessing.
 
Henry Wong
author
Marshal
Pie
Posts: 20836
75
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, assuming that input is a scanner object... basically your code... gets a token from the user and checks if the first letter is "N", if it isn't, it will get another token from the user and checks if the first letter of this new token is "n", if it isn't, it will get another token from the user and checks if the first letter of this new token is "l", if it isn't... so, if you want an "L", you will have to enter it 4 times, with spaces in-between, so that your condition will pass its test. Is this what you wanted?

Henry
 
Campbell Ritchie
Sheriff
Pie
Posts: 47293
52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Agree with Henry.

But, R_ for login, then looking for L?

Maybe you ought to alter your prompts, too.
 
lakmal padmakumara
Ranch Hand
Posts: 47
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for all you people who replied for my question.And after posting my question I found a way to solve my problem.It was exactly the same method Preity has mentioned.And Henry,Yes You are correct about that.Thanks for that valuable tip.
 
Campbell Ritchie
Sheriff
Pie
Posts: 47293
52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're welcome
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic