package cn.wang.day10;
import java.util.Scanner;
public class Demo02_HomeWork {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("请输入字符串,(end表示结束):");
while (true) {
String str = sc.nextLine();
if ("end".equals(str)) {
break;
}
int count = 0;
char[] ch = str.toCharArray();
for (int index = 0; index < ch.length; index++) {
if (ch[index] >= 'A' && ch[index] <= 'Z') {
ch[index] += 32;
count++;
} else if (ch[index] >= 'a' && ch[index] <= 'z') {
ch[index] -= 32;
count++;
} else {
ch[index] = '*';
}
}
System.out.println("转换后的字符串为:" + new String(ch));
System.out.println("总共" + count + "个字母");
}
sc.close();
}
}
转载请注明原文地址:https://ipadbbs.8miu.com/read-5164.html