为什么输出在java中的这个程序中打印Fales5? [英] why the output print Fales5?in this programm in java

查看:55
本文介绍了为什么输出在java中的这个程序中打印Fales5?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  public   class  test {


public static void main( String [] args){

int i = 9 ;
int j = 9 ;
if (i == j)
System。 out .println(< span class =code-string>
True1);
else
系统。 out .println( False1);
字符串 Str1 = Hello;
字符串 Str2 = Hello;
/// /////检查两个物体的包含物//////// ///
if (Str1 == Str2)
System。 out .println( True2);
else
系统。 out .println( False2);
/// ///检查两个对象的包含////////// /
if (Str1.equals(Str2))
System。 out .println( True3);
else
系统。 out .println( False3);
字符串 Str3 = new 字符串 Hello);
字符串 Str4 = new 字符串 Hello);
/// //检查同一位置的等同性/////////// /
if (Str3.equals(Str4))
System。 out .println( True4);
else
系统。 out .println( False4);
/// ////////////////新对象/ /////////
if (Str3 == Str1)
System。 out .println( True5);
else
系统。 out .println( False5);
}

}



输出:

True1

True2

True3

True4

False5

解决方案

查看此内容以获取详细说明。 java - 比较两个相同的字符串,==返回false - Stack Overflow [ ^ ]

public class test {

	
	public static void main(String[] args) {
	
		int i=9;
		int j=9 ;
		if (i==j)
		System.out.println("True1");
		else
		System.out.println("False1");
		String Str1="Hello";
		String Str2= "Hello";
		//////// Check the Contains of two objects///////////
		if (Str1==Str2)
		System.out.println("True2");
		else
		System.out.println("False2");
		//////Check the Contains of two objects///////////
		if (Str1.equals(Str2))
		System.out.println("True3");
		else
		System.out.println("False3");
		String Str3=new String ("Hello");
		String Str4=new String ("Hello");
		///// Check Equality of the same Location ////////////
		if (Str3.equals(Str4))
		System.out.println("True4");
		else
		System.out.println("False4");
		///////////////////New Object //////////
		if (Str3==Str1)
		System.out.println("True5");
		else
		System.out.println("False5");
	}

}


the output:
True1
True2
True3
True4
False5

解决方案

Check this for a breif explanation. java - Comparing two identical strings with == returns false - Stack Overflow[^]


这篇关于为什么输出在java中的这个程序中打印Fales5?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆