+ 3
Why do i get the output "False" with the right input?
This is the Main method: public static void main(String[] args){ Dog one = new Dog(); Mouse two = new Mouse(); print("Dog "); one.givdata(); enter(); print("Mouse "); two.givdata(); enter(); System.out.println("Type py an then press Enter"); Scanner Pr1 = new Scanner(System.in); String Ppr1 = Pr1.next(); /*Here is my Problem my boolean say False boolean Pppr1 = Ppr1=="py"; if(Pppr1==true){ Progrlang py = new Progrlang(); py.pyInfo(); }else{ System.out.println(Pppr1);
4 Réponses
+ 11
Use the following statement :
boolean Pppr1 = Ppr1.equals("py");
Since String is object in Java, it can't be compared using == operator.
+ 8
to compare strings use the equals() method not ==
+ 4
Thx 😀
+ 3
got it thx