这个int是计算的输入的字节数,不是输入的数值,建议你去看一下jdk文档

解决方案 »

  1.   

    我一般用下面的代码读整数。
    DataInputStream in = new DataInputStream(System.in);
    int len = Integer.parseInt(in.readLine());
    System.out.println(len);
      

  2.   

    int intin = System.in.read(b);intin是返回键盘输入 读入字节数组b 中的个数也就是说你这次总共读了4个字节。
      

  3.   

    char x = (char)System.in.read();
    从键盘输入读取一个字符。它只能每次读一个字符出来
    读整数要进行类型转化,楼上正解~~~~~~~~~~
      

  4.   

    我在机器上试了一下
    其实每次System.in.read()就接受一个字符,int是返回这个字符的ACSII码
    我的情况:
    入11
    出49
    入2345
    出50
    入573
    出53
      

  5.   

    楼主,不可能是输出4的,我试了很多次,输入1输出的是49,11还是49,111还是49,这么说明什么呢?说明system.in.read()每次只接受一个字符,返回的是ACSII码。
    如果你想要返回字符的话:char c = (char)System.in.read();这样如果你输入什么,返回的也就是什么,当然也只能接受一个字符,即便你输入再多,返回的也只有一个字符。
      

  6.   

    我的代码:
    import java.io.*;
    import java.lang.*;
    class  readbyte
    {
    public static void main(String[] args) throws java.io.IOException
    {
    byte [] b=new byte [81];
    int intin = System.in.read(b);
    System.out.println(intin);
    }
    }
      

  7.   

    这是read(byte[]b)方法的技术文档
    public int read(byte[] b)
             throws IOException
    Reads some number of bytes from the input stream and stores them into the buffer array b. The number of bytes actually read is returned as an integer. This method blocks until input data is available, end of file is detected, or an exception is thrown. 
    If b is null, a NullPointerException is thrown. If the length of b is zero, then no bytes are read and 0 is returned; otherwise, there is an attempt to read at least one byte. If no byte is available because the stream is at end of file, the value -1 is returned; otherwise, at least one byte is read and stored into b. The first byte read is stored into element b[0], the next one into b[1], and so on. The number of bytes read is, at most, equal to the length of b. Let k be the number of bytes actually read; these bytes will be stored in elements b[0] through b[k-1], leaving elements b[k] through b[b.length-1] unaffected. If the first byte cannot be read for any reason other than end of file, then an IOException is thrown. In particular, an IOException is thrown if the input stream has been close。由第一段第二句可知System.in.read(b);返回的是读入的字节数,还有楼主,我调试过了你的程序,输入11返回的是2,输入111返回的是3。
    System.in.read()方法是有几种参数格式的
    1。System.in.read()  定义:Reads the next byte of data from the input stream. The value byte is returned as an int in the range 0 to 255。
    2。System.in.read(byte []b)  定义如上
    3。System.in.read(byte []b,int off, int len) 建议楼主多看看jdk帮助文档 
      

  8.   

    int intin = System.in.read(b);//返回读入的字符个数,包括回车和换行
    System.out.println(intin);
    具体观察b中元素,可以通过:
      for(int i = 0; i < intin; i++)
         System.out.print(b[i]);
      

  9.   

    不知道各位注意了没有,输入11,输出49;输入2345,输出50时用的是read()。不带参数。返回第一个字符的ascii码。如果你用int intin = System.in.read(b);的话,就返回字节数。虽然11是两个字符,但是后面还有回车符和换行符,所以是4。那么111也就是5了。
      

  10.   

    >>>真不知道为什么,
    我输入
    输入:11
    得:4 
    输入:111
    得:5包含了包括回车和换行!!!!!!
      

  11.   

    为了支持我的观点,运行一下这个程序吧。回车和换行符转化成10进制是10和13。看看最后输出的是不是10和13吧。
    import java.io.*;public class test{
    public static void main(String[] args){
    byte[] b = new byte[20];
    int intin = 0;
    try{
    intin = System.in.read(b);
    }
    catch(IOException e){
    System.out.println(e);
    }
    System.out.println(intin);
    int a = (int)b[intin - 1];
    int c = (int)b[intin - 2];
    System.out.println(a+" "+c);
    }
    }
      

  12.   

    楼主,你可以试一下这个程序
    public class test
    {
       static public void main(String[] args)
       throws Exception
       {
           System.out.print("please input user name: ");
           
           int c = System.in.read();
           
           System.out.println();
           
           if(c == -1)
               System.out.println("Ctrl-C has been pressed!");
           
           System.out.print(c + " ");
           do
           {
               c = System.in.read();
               System.out.print(c + " ");
           }
           while(c != 10);
           
           System.out.println();
       }
    } 你就知道为什么11是4,111是5了,因为最后他总是有个10,13,也就所说的回车跟换行
      

  13.   

    通过这个就看清楚了
    for (int i=0; i<100 ;i++)
    {  
    System.out.println(b[i]);}