为什么第一个输出是Equal,而第二个是Not Equal
来源:学生作业帮 编辑:神马作文网作业帮 分类:综合作业 时间:2024/11/19 02:25:02
为什么第一个输出是Equal,而第二个是Not Equal
public class TestString
{
String st= new String("Hello");
public static void main(String arg[])
{
TestString test = new TestString();
TestString1 test1 = new TestString1();
if(test1.st1 == test1.st2)
System.out.println("Equal");
else
System.out.println("Not Equal");
if(test.st == test1.st1)
System.out.println("Equal");
else
System.out.println("Not Equal");
System.out.println(test.st+"\n"+test1.st1+"\n"+test1.st2);
}
}
class TestString1
{
String st1 = "Hello";
String st2 = "Hello";
}
public class TestString
{
String st= new String("Hello");
public static void main(String arg[])
{
TestString test = new TestString();
TestString1 test1 = new TestString1();
if(test1.st1 == test1.st2)
System.out.println("Equal");
else
System.out.println("Not Equal");
if(test.st == test1.st1)
System.out.println("Equal");
else
System.out.println("Not Equal");
System.out.println(test.st+"\n"+test1.st1+"\n"+test1.st2);
}
}
class TestString1
{
String st1 = "Hello";
String st2 = "Hello";
}
java中“==”比较的是引用变量的地址是否相等,可以用equals方法来比较,equals比较的是内容.
再问: 谢谢啊,equals方法怎么用,我还不会能教一下吗?
再答: 比如:if(test.st.equals(test1.st2)){ ...};试试吧
再问: 谢谢啊,equals方法怎么用,我还不会能教一下吗?
再答: 比如:if(test.st.equals(test1.st2)){ ...};试试吧
equal
为什么是all man are born equal而不是equally
treat sb equal 还说是equally
是equal one还是equals one?
all men are born equal还是were born equal?为什么?
人生而平等 英语翻译成英语是 men are born,equal…对吗?是are 还是were?
请问be equal to是要跟数字吗?
All human being is equal .是哪位名人说的
C语言中的题求最多1000人捐款达到十万时输出捐款人数和捐款平均数,为什么第一个不行而第二个行
The past does not equal the
love and marriage,equal or not?
英语翻译我好象记得是这样:everyone borns equal.可是equal不是副词,怎么修饰born呢?