0
我想將字符串轉換爲大寫字母並返回。 但是我沒有收到預期的輸出。在一個簡單的java程序錯誤
class Exam4{
public static void main(String args[]) throws java.io.IOException{
char ch;
int changes = 0;
System.out.println("Enter a period to stop");
do{
ch = (char) System.in.read();
if (ch >= 'a' & ch <= 'z') {
ch -= 32;
changes++;
System.out.println("ch");
}else if (ch >= 'A' & ch <= 'Z') {
ch+=32;
changes++;
System.out.println("ch");
}
}while(ch != '.');
System.out.println("changes:" + changes);
}
}
你的問題不是很清楚。 同樣對於將來的問題,最好將代碼複製並粘貼到帖子中,格式與代碼一樣。 至於你的錯誤,如果你想打印一個變量,你沒有雙引號。所以只是'System.out.print(ch);' – Vahx 2015-04-04 22:47:09