编程一个java程序

来源:百度知道 编辑:UC知道 时间:2024/05/22 17:34:05
测试两个字符串String fristString=“This is”和String secondString=“This is”是否相等.
将"his father"与其中的firsting字符串连接
用z替换新字符串中的i.

String fristString="This is";
String secondString="This is";
if(fristString.equals(secondString)){
System.out.println("相等");
}
else{
System.out.println("不相等");
}
这个结果输出相等 因为equals这个方法是比较2个字符串内容是否相等

if(fristString==secondString){
System.out.println("相等");
}
else{
System.out.println("不相等");
}
这个输出的是不相等 因为==判断内存地址 判断是否是同一个对象
String是包装类 每次声明都会生成一个新的对象

public class Test{
pblic static void main(String[] args){
String fristString="This is";
String secondString="This is";
System.out.println(fristString.equals(secondString);
}
}
结果为true.
还有楼主,frist打错了吧,应该first.^-^

public class Untitled1 {
public static void main(String[] args) {
String fristString="This is";
String secondString="This is&q