package homework;
import java.util.Scanner;
/*(1)從鍵盤循環(huán)錄入錄入一個字符串,輸入"end"表示結(jié)束
(2)將字符串中大寫字母變成小寫字母,小寫字母變成大寫字母破讨,其它字符用"*"代替,并統(tǒng)計字母的個數(shù)
舉例:
鍵盤錄入:Hello12345World
輸出結(jié)果:hELLO*****wORLD
? 總共10個字母*/
public class Work3 {
public static void main(String[] args) {
String s = end();
System.out.println(s);
cast(s);
}
//利用stringbuffer的append和indexof功能,當(dāng)沒有索引的時候伊者,indexof返回-1? 實現(xiàn)功能(1)
public static String end() {
StringBuffer str = new StringBuffer();
while (true) {
String a = new Scanner(System.in).next();
str.append(a);
if (str.indexOf("end") >= 0) {break;}
}
// System.out.println(str);
return str.toString();
}
//遍歷出字符串的每一個字符串吨拗,重新定義一個stringbuffer箕慧,每次都進行處理
public static void cast(String s) {
StringBuffer str = new StringBuffer(s);
int num = 0;
for (int i =0;i<str.length();i++) {
if (str.charAt(i)>='a' && str.charAt(i)<='z') {
str = str.replace(i, i+1, str.substring(i, i+1).toUpperCase());
num++;
}
else if (str.charAt(i)>='A' && str.charAt(i)<='Z') {
str = str.replace(i, i+1, str.substring(i, i+1).toLowerCase());
num++;
}
else {
str = str.replace(i, i+1, "*");
}
}
/*{
if (str.charAt(i)>='a' && str.charAt(i)<='z') {
str.substring(i,1).toUpperCase();
num++;
}
else if (str.charAt(i)>='A' && str.charAt(i)<='Z') {
str.substring(i,1).toLowerCase();
num++;
}
else {
str.replace(i,1,"*");
}
}*/
System.out.println(str.toString());
System.out.println(num);
}
}