-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCheckString.java
More file actions
31 lines (28 loc) · 617 Bytes
/
CheckString.java
File metadata and controls
31 lines (28 loc) · 617 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
public class CheckString {
public static boolean checkChar(char ch) {
if ((ch + "").getBytes().length == 1) {
return true;
} else {
return false;
}
}
public static String checkString(String str) {
String res = "";
if (str != null) {
for (int i = 0; i < str.length(); i++) {
if (!checkChar(str.charAt(i))) {
res = "中文";
break;
} else {
res = "英文";
}
}
}
return res;
}
public static void main(String[] args) {
String str = "RKJLKJDLKJLSKJLKJ小米手机";
System.out.println("使用长度判断:");
System.out.println(checkString(str));
}
}