read. 输入输出值
怎样使输入的数i以原数出来? Int s=System.in.read(); System.out.println(s);输入1出来49? --------------------编程问答-------------------- System.out.println((char)s); --------------------编程问答-------------------- 不过看它的解释
public abstract int read()
throws IOException
Reads the next byte of data from the input stream. The value byte is returned as an int in the range 0 to 255. If no byte is available because the end of the stream has been reached, the value -1 is returned. This method blocks until input data is available, the end of the stream is detected, or an exception is thrown.
A subclass must provide an implementation of this method.
Returns:
the next byte of data, or -1 if the end of the stream is reached.
还是很奇怪的,并没有提及有关char的信息
/**
* The "standard" input stream. This stream is already
* open and ready to supply input data. Typically this stream
* corresponds to keyboard input or another input source specified by
* the host environment or user.
*/
public final static InputStream in = nullInputStream();
而且in又是final的且被初始化为null --------------------编程问答--------------------
我查了一下api
楼上的前辈也发了一个帖子的
http://bbs.csdn.net/topics/390415810 --------------------编程问答-------------------- 用char只对0~9的数字合适,再高就不行了,怎么办? --------------------编程问答-------------------- 楼主看看java IO 流吧
InputStreamReader in = new InputStreamReader ( System.in);
int temp = in.read();
char target ;
if(temp != -1){
target = (char)temp;
}
补充:Java , Java SE