import java.io.*;public class Findsort
{
public static void main(String[] args) throws IOException
{
BufferedInputStream in = new BufferedInputStream(System.in);
BufferedOutputStream out = new BufferedOutputStream(System.out);
int y[] = {2,4,5,7,9,0};
int a,l = 0;
byte b[] = new byte[2];

System.out.print("Please enter the wanting number : ");
a = in.read(b,0,2);

for(int i = 0;i < 6;i++)
{
if(y[i] == a)
{
  l = 1;
  break;
}
}

if(l == 0)
{
out.write(b,0,1);
System.out.println("NO found!");
out.flush();
}
else
  System.out.println("Found!");
}
}
请问这个程序错在哪里啊?为什么l的值总是1呢?
还有就是out.write(b,0,1)这一句有什么作用呢?

解决方案 »

  1.   

    测试了下,
    a = in.read(b,0,2);
    这里,总是得到2
    那就是逻辑错误了
      

  2.   

    为什么l的值总是1呢?====>  a = in.read(b,0,2); 中的Read 函數返回的是讀取的字節數,無論你輸入什麽值, 返回的就是2個字節
    还有就是out.write(b,0,1)这一句有什么作用呢?====> b 為讀入數據的緩沖區,這裏指調用out引用對象指向該緩沖區,然後對些緩沖區數據進行輸出.
      

  3.   

    a = in.read(b,0,2);
    这个是读取的字节数,当然所有的都是2