-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWordConversion.java
More file actions
29 lines (27 loc) · 860 Bytes
/
WordConversion.java
File metadata and controls
29 lines (27 loc) · 860 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
public class WordConversion {
//大写转小写
public static String toLowerCase(String str) {
char [] a = str.toCharArray();
for (int i = 0;i < str.length();i++) {
if (a[i] >= 65 && a[i]<= 90) {
a[i] = (char)(a[i] + 32);
}
}
return new String(a);
}
//小写转大写
public static String toHigherCase(String str) {
char [] a = str.toCharArray();
for (int i = 0;i < str.length();i++) {
if (a[i] >= 97 && a[i]<= 122) {
a[i] = (char)(a[i] - 32);
}
}
return new String(a);
}
public static void main(String[]args){
String str = "Hello World";
System.out.println("大写转小写:"+toLowerCase(str));
System.out.println("小写转大写:"+toHigherCase(str));
}
}