0
because this code doesn't work, help!!
import java.util.Scanner; public class Program { public static void main(String[] args) { Scanner escaner = new Scanner (System.in); String word = escaner .nextLine(); String x = "password"; if (word==x) System.out.println("nice"); } }
2 odpowiedzi
+ 6
For string comparisons use equals() method always :
if(word.equals(x))
System.out.println("nice");
+ 4
== checks if both Strings point to the same memory location
.equals() evaluates to the comparison of values in the Strings.