似乎看到几个方法,不知道那个最好,先列出来,等研究出来再更新:
public static void main(String[] args) {
System.out.println("please type in an integer: ");
int i=Integer.parseInt(args[0]);
}
------------------------------------------------
int n;
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String str = br.readLine();
n = Integer.parseInt(str);
------------------------------------------
public static char readChar()
{
int charAsInt=-1;//to keep the compiler happy
try
{
charAsInt=System.in.read();
}
catch (IOException e)
{
System.out.println(e.getMessage());
System.out.println("Fatal error.Ending program.");
System.exit(0);
}
return (char)charAsInt;
}
---------------------------------------------
byte[] buffer=new byte[512];
System.in.read(buffer);
String str=new String(buffer);
没有评论:
发表评论