2

Here is my working code. However, one small problem. I cannot seem to input in the right answer. The code always only repeats "Incorrect. Wrong answer..." even if I input the right answers which are "slowbro", "Slowbro", and "SLOWBRO". I would be very thankful if someone can help me fix the following code:

public void PokemonQuiz ()
{
char again = 'y';
while (again == 'y' ||  again == 'Y') {
 String ans = IBIO.inputString ("\nUnscramble: OBORSLW (Hint: Shelder latches onto its tail.) ");
 int tries = 0;

 while (ans != "slowbro" || ans != "Slowbro" || ans != "SLOWBRO") {
  System.out.println ("Incorrect. Wrong answer. Try again.");
  tries++;
  ans = IBIO.inputString ("\nUnscramble: OBORSLW (Hint: Shelder latches onto its tail.) ");

  if (tries > 3)
  {
   System.out.println ("The correct answer was SLOWBRO.");
   again = IBIO.inputChar ("Play again? (y/n) ");

   if (again != 'y' || again != 'Y')
    break;
  }
  }
  System.out.println ("Correct.");
  }

Edit: I know that "==" should be replaced with ".equals ()" but then how would i change the "!=" ??

lkjhgfdsa4321
  • 43
  • 1
  • 11
  • I understand that == should be replaced with .equals () but how do i change the != that i used – lkjhgfdsa4321 Apr 01 '16 at 22:36
  • 1
    True enough and perhaps try: while (!ans.toLowerCase().equals("slowbro")) {..... instead of: while (ans != "slowbro" || ans != "Slowbro" || ans != "SLOWBRO") {.... – DevilsHnd - 退職した Apr 01 '16 at 22:40
  • also, i can't change my (again == 'y') since char is not a reference type so can you please explain why my question was closed since it clearly is not solved? – lkjhgfdsa4321 Apr 01 '16 at 22:41
  • @ DevilsHnd never mind, it displays "correct" now, but how can i prevent the loop from looping over and over again? – lkjhgfdsa4321 Apr 01 '16 at 22:54
  • @DevilsHnd my bad accidentally left a space after the @ sign. Please answer my questions ^^ – lkjhgfdsa4321 Apr 01 '16 at 22:58
  • 1
    Sorry for the delay. Since this post is closed to providing a specific answer you can view a solution here: http://freetexthost.com/d4art1zaon Just follow that sort of model. – DevilsHnd - 退職した Apr 02 '16 at 21:13
  • @DevilsHnd sorry for bothering you, but can you please help me with another problem at http://stackoverflow.com/questions/36390000/calling-method-parameters-is-not-working?noredirect=1#comment60397483_36390000 . This would help me a lot. Thanks in advance. – lkjhgfdsa4321 Apr 03 '16 at 19:57

0 Answers0