gpt4 book ai didi

java - 简单的 string.equals() if 语句不工作 Java

转载 作者:搜寻专家 更新时间:2023-11-01 01:08:08 26 4
gpt4 key购买 nike

<分区>

我快要疯了。也许是因为我已经工作了 12 个小时....但是为什么我的 if 语句在运行 if (band.equals("4384") 时不计算为真??我正在打印 band 到屏幕,它正在读取 4384 但它不会计算为真。我已经使用 .equals() 很多次了,没有问题,我做错了什么?

public class Test {

public static void main(String[] args) {
// TODO Auto-generated method stub

String endBand = " ";

String str = "SCELL: UARFCN 4384, Prim. SC: 362, RSCP: 70, EcNo: 44";

endBand = getBandNumber(str);

System.out.println("endBand is " + endBand);

}

// ************************************************
// Returns the current band that the device is on.
// Currently only coded for 3G
// ************************************************
private static String getBandNumber(String str) {

// The string returned to str will be in the form of:
// "SCELL: UARFCN 4384, Prim. SC: 362, RSCP: 73, EcNo: 33"
// ^^^^
// String str = read_AT("AT+XL1SET=\"IRATSCEL?\"", 10);

String band = " ";
int begin = 0, end = 0;

// Filter through the string to extrace the channel number
for (int i = 0; i < str.length(); i++) {

char c = str.charAt(i);

if (c == 'N' && str.charAt(i + 1) == ' ') {

begin = i + 1;

} else if (c == ',') {

end = i;

break;

}

}

band = str.substring(begin, end);
System.out.println("band is " + band);

if (band.equals("4384")) {

band = "5";

} else {

band = "2";
}

return band;

}

}

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com