This discussion is archived
1 Reply Latest reply: Jan 13, 2013 12:54 AM by PhHein RSS

Input/String Help?

984458 Newbie
Currently Being Moderated
import java.util.Scanner;
class bc {
     public static void main(String[] args) {
          Scanner o = new Scanner(;
          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?
    PhHein Guru Moderator
    Currently Being Moderated
    Formatting code is dscribed in the announcements:
    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.


  • Correct Answers - 10 points
  • Helpful Answers - 5 points