读取控制台的字符串_方法一

public static String getString()throws IOException{
    InputStreamReader isr = new InputStreamReader(System.in);
    BufferedReader br = new  BufferedReader(isr);
    String s =br.readLine();
    return s;
}
public static int getInt() throws IOException{
    String s = getString();
    return Integer.parseInt(s);
}
public static void main(String[] args) throws IOException {
    System.out.println("Enter a number :");
     theNumber = getInt();
    System.out.println("The number is "+theNumber);
}

 

posted @ 2013-07-11 11:55  王超_cc  阅读(343)  评论(0编辑  收藏  举报