if((b=System.in.read())!=-1),不理解这个语句 b=System.in.read()应该是true,或者是false,那怎么能和-1作运算

解决方案 »

  1.   

    去查一下API,看read()究竟返回什么值。
    abstract  int read() Reads the next byte of data from the input stream
      

  2.   

    System.in 是一个InputStream 类的对象 System.in.read() 返回的是一个int值
     
    自己看看API
              
      

  3.   

    if((b=System.in.read())!=-1)
    相当于
    if((System.in.read())!=-1)
    也相当于
    if((b!=-1)in.read()方法返回的是读取到的字符的ASCII码值.是一个int型的.这个方法定义了一个返回值-1.表示没有读到到任何东西..
    就是说没有读到任何东西的话返回-1..然后这句话的意思就是:
    if(没有读到东西)
      

  4.   

    如果想返回一个字符,可以用
    (char)System.in.read()