1.從鍵盤回圈錄入錄入一個字串,輸入"end"表示結束
2.將字串中大寫字母變成小寫字母,小寫字母變成大寫字母,其它字符用"*"代替,并統計字母的個數
舉例:
鍵盤錄入:Hello12345World
輸出結果:hELLO*****wORLD
public class Work2 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("請輸入一個字串:");
while(true) {
System.out.println("");
String m = sc.nextLine();
if (m.equals("end")) {
System.out.println("over!");
return;
}
System.out.println("想要退出回圈輸入end");
for (int i = 0; i < m.length(); i++) {
if (m.charAt(i) >= 'A' && m.charAt(i) <= 'Z') {
String a = "";
a += m.charAt(i);
System.out.print(a.toLowerCase());
} else if (m.charAt(i) >= 'a' && m.charAt(i) < 'z') {
String b = "";
b += m.charAt(i);
System.out.print(b.toUpperCase());
} else if ((int) m.charAt(i) >= 48 && (int) m.charAt(i) <= 57) {
String ccc = "";
ccc += m.charAt(i);
System.out.print("*");
}
}
}
}
}
驗證:

轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/213035.html
標籤:其他
上一篇:Java寫的第一個小游戲
