1
0
mirror of https://github.com/Snailclimb/JavaGuide synced 2025-08-05 20:31:37 +08:00

Merge pull request #299 from chndgh/master

Fix wrong logic
This commit is contained in:
SnailClimb 2019-05-07 16:40:45 +08:00 committed by GitHub
commit 8f1cae3ba6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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,20 +135,16 @@ public class Main {
} }
private static boolean chechStrs(String[] strs) { private static boolean checkStrs(String[] strs) {
boolean flag = false;
// 注意:=是赋值,==是判断
if (strs != null) { if (strs != null) {
// 遍历strs检查元素值 // 遍历strs检查元素值
for (int i = 0; i < strs.length; i++) { for (int i = 0; i < strs.length; i++) {
if (strs[i] != null && strs[i].length() != 0) { if (strs[i] == null || strs[i].length() == 0) {
flag = true; return false;
} else {
flag = false;
} }
} }
} }
return flag; return true;
} }
// 测试 // 测试