public class TestString {
public static void main(String args[]) {
String upper = "ABCDEFGLAKAKJGALKSDA";
for (int i = 0; i < upper.length(); i++) {
System.out.print(upperCaseToLowerCase(upper.charAt(i)));
}
}
public static char upperCaseToLowerCase(char ch) {
char vch;
vch = (char) (ch +32);
return vch;
}
}
结果:
abcdefglakakjgalksda
接口实现都已近告诉你了,你也忒懒了点,从 javax.swing.JOptionPane 获取数据再往里面传就行了嘛!! 看样子你真不懂 java,下面可以运行:
package com;
import javax.swing.JOptionPane;
public class Test {
public static void main(String args[]) {
String upper = JOptionPane.showInputDialog(null, "请输入字符串");
System.out.println(upperStrToLowerStr(upper));
}
public static String upperStrToLowerStr(String upper) {
String lower = "";
for (int i = 0; i < upper.length(); i++) {
lower += upperCaseToLowerCase(upper.charAt(i));
}
return lower;
}
public static char upperCaseToLowerCase(char ch) {
if (ch >= 65 && ch <= 90) { //如果是大写字母就转化成小写字母
ch = (char) (ch + 32);
}
return ch;
}
}
测试输入:ASDBC2334Qasdfsa
输出: asdbc2334qasdfsa
温馨提示:答案为网友推荐,仅供参考