import java.io.*;
public class TheCommandInput
{
public static void main(String args[])
{
String str;
InputStreamReader isr;
BufferedReader br;
try
{
System.out.println("Pls. input a int number:");
isr=new InputStreamReader(System.in);
br=new BufferedReader(isr);
str=br.readLine();
System.out.println("the input valueis:"+str);
int i=Integer.parseInt(str);
i=i*2;
System.out.println("input value changeed after doubled:"+i);
}
catch(IOException e)
{
System.out.println("have a IOException");
}
}
}
//end
功能說明:從命令行中接受一個整數(shù),將其乘上2后再系統(tǒng)輸出。
關(guān)鍵要素說明:InputStreamReader 是將標(biāo)準(zhǔn)輸入字節(jié)流轉(zhuǎn)換為用于輸入的字符流;BufferedReader將字符流轉(zhuǎn)換為緩沖流,利用緩沖流的API的函數(shù)readLine()讀入命令行輸入的一行字符,并賦值給字符串變量。
posted on 2006-08-17 14:19
wqwqwqwqwq 閱讀(508)
評論(0) 編輯 收藏