题目:
从键盘循环录入录入一个字符串,输入"end"表示结束
将字符串中大写字母变成小写字母,小写字母变成大写字母,其它字符用"*"代替,并统计字母的个数
举例:
键盘录入:Hello12345World
输出结果:hELLO*****wORLD
/**
* 字符串内大小写转换
* @author littleRich
*
*/
public class CaseConversion {
public static void main(String[] args) {
while(true){
Scanner scan = new Scanner(System.in);
System.out.println("Please input a String:");
String str = scan.next();
StringBuffer sb = new StringBuffer();
if(str.equals("end")){
System.out.println("The Program has been shutdown...");
System.exit(0);
}else{
for(int i = 0 ; i < str.length(); i++){
char temp = str.charAt(i);
if(temp >= 'a' && temp <= 'z'){
temp = (char)(temp-32);
}else if(temp >= 'A' && temp <= 'Z'){
temp = (char)(temp + 32);
}else{
temp = '*';
}
sb.append(temp);
}
}
System.out.println(sb.toString());
}
}
}