接受屏幕輸入轉換爲大寫 via InputStreamReader & System.in

import java.io.*;
public class TestTransformReader {

	public static void main(String[] args) {
		InputStreamReader isr = new InputStreamReader(System.in);
		BufferedReader br = new BufferedReader(isr);//這裏再套用緩衝流是因爲要用到readLine()方法
		String str = null;
		try{
			str = br.readLine();
			while(str != null){
				if(str.equalsIgnoreCase("exit")){
					break;
				}
				System.out.println(str.toUpperCase());
				str = br.readLine();
			}
			br.close();
		}catch(IOException ioe){
			ioe.printStackTrace();
		}
	}
}
IOException涵蓋了大部分io報錯,比如FileNotFoundException。
發佈了67 篇原創文章 · 獲贊 6 · 訪問量 6萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章