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"); } }

7th Mar 2022, 8:37 PM
Y43l
Y43l - avatar
2 odpowiedzi
+ 6
For string comparisons use equals() method always : if(word.equals(x)) System.out.println("nice");
7th Mar 2022, 8:41 PM
Jayakrishna 🇮🇳
+ 4
== checks if both Strings point to the same memory location .equals() evaluates to the comparison of values in the Strings.
7th Mar 2022, 8:51 PM
kev_coding
kev_coding - avatar