在手边的问题是每个策略号是9个字符的字符串,其中表示保单排序由第一字符
- B的类型建立政策 为内容
- Ç政策
- L用汽车政策
每个保单号码的其余8个字符的生命政策
我一直在使用的charAt尝试,但有人告诉我有一个稍微好一点的办法
public String getpolicyNo(String initpolicyNo) {
/**
* Access method to find the first character of the policy to then
* determine what type of policy it is.
*/
String b = "B";
String C = "C";
String L = "L";
String V = "V";
char c1 = b.charAt(0);
char c2 = C.charAt(0);
char c3 = L.charAt(0);
char c4 = V.charAt(0);
if (c1 == 0) {
System.out.println("Its building" + c1);
return initpolicyNo;
} else {
if (c2 == 0) {
System.out.println("Its Content");
return initpolicyNo;
} else {
if (c3 == 0) {
System.out.println("Its life");
return initpolicyNo;
} else {
if (c4 == 0) {
System.out.println("Its car");
return initpolicyNo;
}
}
}
}
throw new IllegalArgumentException();
}
我不是找你提供给我一个答案,我只是在寻找任何可能的替代品和可能的建议。
非常感谢
丹
您可以使用'之开关来代替。休息很好。 – 2013-03-04 12:14:33
由于c1-4是字符,你怎么比较它为0? – aa8y 2013-03-04 12:15:21
你不想比较initpolicyNo.chartAt(0)吗? – BobTheBuilder 2013-03-04 12:16:28