Java 我的目标是从这两个方法中获得cType和cSize的值,但它会不断返回;nullnull"; 公共类主 { 静态字符串clotheOrder[]={“FB02”,null,null,null,“TS03”,“GS04”,null,“PA03”}; intClothEquantity[]={3,0,2,0,2,2,0,0}; 静态字符串cType,cSize; ``` 公共静态void main(字符串[]args){ 对于(int x=0;x
,在我看来,您的问题之一是由于使用引用比较(Java 我的目标是从这两个方法中获得cType和cSize的值,但它会不断返回;nullnull"; 公共类主 { 静态字符串clotheOrder[]={“FB02”,null,null,null,“TS03”,“GS04”,null,“PA03”}; intClothEquantity[]={3,0,2,0,2,2,0,0}; 静态字符串cType,cSize; ``` 公共静态void main(字符串[]args){ 对于(int x=0;x,java,Java,,在我看来,您的问题之一是由于使用引用比较(=)而不是值比较(.equals) 另一个原因是正则表达式字符串的作用与您想要的相反 交换正则表达式字符串,并将==更改为.equals(),函数应该可以正常工作。Hi@AugustusMoran,欢迎使用堆栈溢出。获取null的原因是java使用.equals()()来比较字符串。您可以使用say开关(大小){case“01”:..或将==更改为.equals()以使其工作。 public class Main { static String
=
)而不是值比较(.equals
)
另一个原因是正则表达式字符串的作用与您想要的相反
交换正则表达式字符串,并将
==
更改为.equals()
,函数应该可以正常工作。Hi@AugustusMoran,欢迎使用堆栈溢出。获取null的原因是java使用.equals()
()来比较字符串。您可以使用say开关(大小){case“01”:..
或将==更改为.equals()以使其工作。
public class Main
{
static String clotheOrder[] = {"FB02", null, null, null, "TS03", "GS04", null, "PA03"};
int clotheQuantity[] = {3, 0, 2, 0, 2, 2, 0, 0};
static String cType, cSize;
```
public static void main(String[] args) {
for (int x = 0; x <= clotheOrder.length; x++) {
if (clotheOrder[x] == null) {
System.out.println("No order");
continue;
}
else {
System.out.println(clotheType(clotheOrder[x].replaceAll("[^0-9]", ""))
+ clotheSize(clotheOrder[x].replaceAll("[^A-Z]", "")));
}
}
}
static String clotheType(String type) {
if (type == "FB" ) {cType = "Blouse .............";}
else if (type == "TS" ) {cType = "T-Shirt ............";}
else if (type == "GS" ) {cType = "Garterized Shorts ..";}
else if (type == "PA" ) {cType = "Pants ..............";}
else if (type == "PS" ) {cType = "Pencil Skirt .......";}
else if (type == "CC" ) {cType = "Chinese Collar Polo ";}
else if (type == "PW" ) {cType = "White Slacks .......";}
else if (type == "RB" ) {cType = "Round Neck Blouse ..";}
else if (type == "S" ) {cType = "Skirt ..............";}
else if (type == "VN" ) {cType = "V-Neck Polo ........";}
return cType;
}
static String clotheSize(String size) {
if (size == "01") {cSize = " (Extra-Small) ...";}
else if (size == "02") {cSize = " (Small) .........";}
else if (size == "03") {cSize = " (Medium) ........";}
else if (size == "04") {cSize = " (Large) .........";}
else if (size == "05") {cSize = " (X-Large) .......";}
else if (size == "06") {cSize = " (2X-Large) ......";}
else if (size == "07") {cSize = " (3X-Large) ......";}
else if (size == "08") {cSize = " (Add-ons) .......";}
return cSize;
}
}
```