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";
}
}
}
前两个if肯定不满足啊,字符串相等不能用==,得用equals
==是要求两侧的字符串是同一个对象,equals是要求两侧字符串内容相同