Vswe's Summer Courses | You're not logged in. Sign up or log in | Server time: | Donate
One can now see other persons' badge hunts. Simply head over to their profiles to access them.

Go back to course page

Thinking with objects

Object orientated programming in Java

Using scanner with Strings

  • 2013-07-22 13:54:45
    I have this code, but I don't know why it isn't working:
    Scanner scanner = new Scanner(System.in);
    System.out.println("Do you want to play again? (y/n)");

    if (scanner.nextLine().toLowerCase() == "y") {
    System.out.println("Playing again")

    But when I type "y", it doesn't work, and when I store the output of the scanner in a string and print it, it outputs "y".

    I have no clue what I'm doing wrong :/
  • 2013-07-22 15:33:59
    You will have to do scanner.nextLine().toLowerCase().equals("y")
  • 2013-07-22 16:39:01
    Thanks, now I'm almost done :D
  • Log in or sign up to reply to this thread