生活随笔
收集整理的這篇文章主要介紹了
标准输入流【应用】
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
public class SystemInDemo {public static void main(String[] args) throws IOException {//public static final InputStream in:標(biāo)準(zhǔn)輸入流
// InputStream is = System.in;// int by;
// while ((by=is.read())!=-1) {
// System.out.print((char)by);
// }//如何把字節(jié)流轉(zhuǎn)換為字符流?用轉(zhuǎn)換流
// InputStreamReader isr = new InputStreamReader(is);
// //使用字符流能不能夠?qū)崿F(xiàn)一次讀取一行數(shù)據(jù)呢?可以
// //但是,一次讀取一行數(shù)據(jù)的方法是字符緩沖輸入流的特有方法
// BufferedReader br = new BufferedReader(isr);BufferedReader br = new BufferedReader(new InputStreamReader(System.in));System.out.println("請輸入一個字符串:");String line = br.readLine();System.out.println("你輸入的字符串是:" + line);System.out.println("請輸入一個整數(shù):");int i = Integer.parseInt(br.readLine());System.out.println("你輸入的整數(shù)是:" + i);//自己實現(xiàn)鍵盤錄入數(shù)據(jù)太麻煩了,所以Java就提供了一個類供我們使用Scanner sc = new Scanner(System.in);}
}
?
總結(jié)
以上是生活随笔為你收集整理的标准输入流【应用】的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。