package com.example.demo3;
public class Demo3Application {
public static void main(String[] args) {
String str = "112000";
String substring = str.substring(4, 6);
System.out.println(substring);
String type = type(str);
System.out.println(type);
}
private static String type(String code){
if(code.contains("0000")){
return "1";
}else if (code.substring(4,6) == "00") {
return "2";
}else {
return "3";
}
}
}

为什么调用下面的type方法返回的结果是3,求解惑~~
- 写回答
- 好问题 0 提建议
- 关注问题
- 邀请回答
-
1条回答 默认 最新
- 快乐鹦鹉 2022-06-17 14:33关注
前两个if肯定不满足啊,字符串相等不能用==,得用equals
==是要求两侧的字符串是同一个对象,equals是要求两侧字符串内容相同本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 2无用