mirror of
https://github.com/Snailclimb/JavaGuide
synced 2025-06-25 02:27:10 +08:00
original implementation cannot handle {"customer", "", "car"}
This commit is contained in:
parent
f346c81e64
commit
f46d1a74b4
@ -112,7 +112,7 @@ public class Main {
|
|||||||
public static String replaceSpace(String[] strs) {
|
public static String replaceSpace(String[] strs) {
|
||||||
|
|
||||||
// 如果检查值不合法及就返回空串
|
// 如果检查值不合法及就返回空串
|
||||||
if (!chechStrs(strs)) {
|
if (!checkStrs(strs)) {
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
// 数组长度
|
// 数组长度
|
||||||
@ -135,21 +135,17 @@ public class Main {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean chechStrs(String[] strs) {
|
private static boolean checkStrs(String[] strs) {
|
||||||
boolean flag = false;
|
if (strs != null) {
|
||||||
// 注意:=是赋值,==是判断
|
// 遍历strs检查元素值
|
||||||
if (strs != null) {
|
for (int i = 0; i < strs.length; i++) {
|
||||||
// 遍历strs检查元素值
|
if (strs[i] == null || strs[i].length() == 0) {
|
||||||
for (int i = 0; i < strs.length; i++) {
|
return false;
|
||||||
if (strs[i] != null && strs[i].length() != 0) {
|
}
|
||||||
flag = true;
|
}
|
||||||
} else {
|
}
|
||||||
flag = false;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
return flag;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 测试
|
// 测试
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user