Hi guys, I'm new to Java programming and I ran into a problem that I don't know how to solve. I'd appreciate it if anyone could help me.
So, I'm trying to run an if statement with an input condition and here is my code.
import java.util.Scanner;
public class App10A {
public static void main(String[] args) {
Scanner fun = new Scanner(System.in);
System.out.println("What's your name?");
String name = fun.nextLine();
if (name == "Victor") {
System.out.println("This is the result I wanted!");
}
else {
System.out.println("Oops, try again!");
}
}
}
When the computer asked me "What's your name?", I typed in Victor, then the result turned out to be "Oops, try again!".
I typed in Victor (without parenthesis) and "Victor" and both gave me the negative results.
What exactly should I put in in order to get "This is the result I wanted!" ?
Or, how should I modify my code in order to get "This is the result I wanted!" when I put in Victor (without changing the equal sign)?