1 Reply Latest reply on Jan 13, 2013 8:54 AM by PhHein

    Input/String Help?

      import java.util.Scanner;
      class bc {
           public static void main(String[] args) {
                Scanner o = new Scanner(System.in);
                String a;
                     System.out.print("Input Something: ");
                     a = o.nextLine();
                     if(a == "hey") {
           public static void Back(){
                System.out.println("Hey, there.");

      How do I make this properly work where if the user inputs "hey", it will print out the method Back, instead of just "Invalid"?

      P.S. How do I make my Java code in format for the forums?
        • 1. Re: Input/String Help?
          Formatting code is dscribed in the announcements: https://forums.oracle.com/forums/ann.jspa?annID=1389
          Please search for Java coding conventions, especially what is capitalized and what not.
          Strings are never compared with == , that's why you get unexpected results. I suggest you look at the tutorials.

          Moderator action: moving this thread to NTJ.