0

I used this code:

Scanner SC = new Scanner(System.in);
String Gender = " ";
System.out.println("....");
String Ans1 = SC.nextLine();
Ans1 = Ams1.toLowerCase();
if(Ans1 == "yes") {
  Gender = "male";
  System.out.println(Gender);
}
else {
System.out.println("Get out!");
}

I think I used the Gender variable in if statement, but it's showing The Value of the local Variable is not used.

And when I ran, it works but the value of gender is the same as the previous. It means that if I write yes it doesn't show the word male it shows the space I gave.

Please Help!

rensothearin
  • 670
  • 1
  • 5
  • 24
  • @Tech Your code will not *compile* because of typo at `Ans1 = Ams1.toLowerCase();` where you have `Ams1.toLowerCase()` instead of `Ans1.toLowerCase();`. But even after fixing that typo I still can't reproduce your problem (which I am assuming is *warning* from Eclipse IDE). That confirms your suspicion that this warning shouldn't appear in the first place because of `System.out.println(Gender);` which is actually *using/reading* value of `Gender`. Can you still reproduce that problem after fixing that typo and/or restarting Eclipse or using Project->Clean? – Pshemo Nov 26 '20 at 15:39

1 Answers1

-2

@Tech Minds Aditya, You have written Ans1 = Ams1 instead of Ans1 = Ans1

  • While it is nice you are trying to help OP problems which are only caused by typos are quite "unique" meaning that they have very low chance to repeat and being useful for others. That is why we don't really want to gather such questions here on Stack Overflow. You can helo OP by informing him/her about it via *comment* when you will gather 50 reputation points (which isn't that hard). But posting such information via answer is not best idea because if answer will get positive score or will be accepted (marked as solution) it will prevent our automatic deletion system from removing it. – Pshemo Nov 26 '20 at 15:59
  • Anyway don't get discouraged by that, mistakes are inevitable at start which includes using this site. Also if you want to get back reputation points lost by downvotes on this post you can do it by deleting it (your reputation should be back after recalculation which is triggered every few minutes). – Pshemo Nov 26 '20 at 16:02