public class test2 {
/** test
*
*/
public static void main(String args[]) {
String str ="asfdf123BNHNN@#%^$";
System.out.println("**=" +str);
String re1 ="[a-z]";
String re2 = "[A-Z]";
// 1
StringBuffer sb = new StringBuffer();
for(int i=0; i< str.length(); i++){
String strTmp = "" + str.charAt(i);
if(strTmp.matches( re1)) {
strTmp = strTmp.toUpperCase();
} else if(strTmp.matches( re2)){
strTmp = strTmp.toLowerCase();
}
sb.append(strTmp);
}
System.out.println(sb.toString());
// 2
sb = new StringBuffer();
for(int i=0; i< str.length(); i++){
int intAC2 = (int)str.charAt(i);
String strTmp = "" + str.charAt(i);
if(intAC2>64 && intAC2 < 91) { // A-Z
strTmp = strTmp.toLowerCase();
} else if(intAC2>96 && intAC2 < 123){ // a-z
strTmp = strTmp.toUpperCase();
}
sb.append(strTmp);
}
System.out.println(sb.toString());
}
}
/** test
*
*/
public static void main(String args[]) {
String str ="asfdf123BNHNN@#%^$";
System.out.println("**=" +str);
String re1 ="[a-z]";
String re2 = "[A-Z]";
// 1
StringBuffer sb = new StringBuffer();
for(int i=0; i< str.length(); i++){
String strTmp = "" + str.charAt(i);
if(strTmp.matches( re1)) {
strTmp = strTmp.toUpperCase();
} else if(strTmp.matches( re2)){
strTmp = strTmp.toLowerCase();
}
sb.append(strTmp);
}
System.out.println(sb.toString());
// 2
sb = new StringBuffer();
for(int i=0; i< str.length(); i++){
int intAC2 = (int)str.charAt(i);
String strTmp = "" + str.charAt(i);
if(intAC2>64 && intAC2 < 91) { // A-Z
strTmp = strTmp.toLowerCase();
} else if(intAC2>96 && intAC2 < 123){ // a-z
strTmp = strTmp.toUpperCase();
}
sb.append(strTmp);
}
System.out.println(sb.toString());
}
}
解决方案 »
- java泛型实现加法
- jtable 列冻结问题?
- 关于java的private为什么类外不能用对象引用.变量名访问,而必须用共有的方法访问?
- 求Java Swing 中JCheckBox 不灰化 也不让修改其选中状态的方法。
- 请教为什么包含java内部类的方法,它的参数必需为final的问题?
- 在一台计算机上用VE做了个JFrame,换到另一台计算机上就不会操作了。
- 请问怎样实现图片的反色显示,旋转,剪切??----在线等 急急!!
- 请问如何让Tab键遍历所有控件?
- 如何把对象发送到远程主机,远程主机如何把发送过来的对象流还原??
- Java中^这个符号怎么用,
- 还是一个简单程序的问题
- Java中如何实现对文本文件的插入文本,删除文本等操作
public static void main(String args[]) {
String str =javax.swing.JOptionPane.showInputDialog("请输入一个字符串:");
System.out.println("你输入的是:" +str);
String re1 ="[a-z]";
String re2 = "[A-Z]";
StringBuffer sb = new StringBuffer();
for(int i=0; i< str.length(); i++){
String strTmp = "" + str.charAt(i);
if(strTmp.matches( re1)) {
strTmp = strTmp.toUpperCase();
} else if(strTmp.matches( re2)){
strTmp = strTmp.toLowerCase();
}
sb.append(strTmp);
}
System.out.println("转换为:"+sb.toString());
sb = new StringBuffer();
for(int i=0; i< str.length(); i++){
int intAC2 = (int)str.charAt(i);
String strTmp = "" + str.charAt(i);
if(intAC2>64 && intAC2 < 91) {
strTmp = strTmp.toLowerCase();
} else if(intAC2>96 && intAC2 < 123){
strTmp = strTmp.toUpperCase();
}
sb.append(strTmp);
}
}
}
记得给分啊!