简单的检查操作在java中不起作用[重复]

时间:2022-08-05 16:47:04

This question already has an answer here:

这个问题在这里已有答案:

String TypedMaxNumber = MaxValue.getText();
if(TypedMaxNumber == "100")
    System.out.println(TypedMaxNumber+" = 100");

I think it is a silly problem, but when I am running to run this program and I type 100 in the text Field it is not going inside the loop. What could be the reason.

我认为这是一个愚蠢的问题,但是当我运行这个程序并在文本字段中输入100时,它不会进入循环。可能是什么原因。

1 个解决方案

#1


1  

I am running to run this program and I type 100 in the text Field it is not going inside the loop.

我正在运行这个程序,我在文本字段中输入100,它不会进入循环内部。

Its

if(TypedMaxNumber.equals("100"))

Since TypedMaxNumber is of type String. equals() check for value equality

由于TypedMaxNumber的类型为String。 equals()检查值的相等性

#1


1  

I am running to run this program and I type 100 in the text Field it is not going inside the loop.

我正在运行这个程序,我在文本字段中输入100,它不会进入循环内部。

Its

if(TypedMaxNumber.equals("100"))

Since TypedMaxNumber is of type String. equals() check for value equality

由于TypedMaxNumber的类型为String。 equals()检查值的相等性