DataInputStream dis=new DateInputStream(System.in);
a=dis.readline;
....
b=dis.readline;
....
需要缓冲。

解决方案 »

  1.   

    read和readln不同阿
    read(byte[] b)
    改成readln吧
      

  2.   

    回车被认为是B了。
    DataInputStream dis=new DateInputStream(System.in);
    不行啊
    我编译了一下会出现错误
    cannot resolve symbol
    symbol  : class DateInputStreamnew DateInputStream(System.in);这样的写法有错吧
      

  3.   

    ?查了一把api,没有readln的啊:(
    那就只有自己判断了
    用read(),一次读一个,然后凑起来
      

  4.   

    System.in.read()读入的是key 的编码
    在你输入一个数后,按 enter key 时,己输入了b,b=enter 的编码
     你在d=System.in.read(); 后  insert   System.out.println(*a=*+a+*b=*);
    观察结果
      

  5.   

    byte[] aa = new byte[2000];
    int num = System.in.read(aa);
    num是读到的byte总数。只要你一行输入不超过2000个byte就能保存在aa里面
    你可以再定义一个bb = new byte[num];就可以了。
      

  6.   

    try {
                            System.out.print("请输入a:");
                            byte[] aa = new byte[300];
          a = System.in.read(aa);
                            //a = System.in.read();
                            System.out.print("请输入b:");
                            byte[] bb = new byte[300];
          b = System.in.read(bb);
                            //b = System.in.read();
                            System.out.println("a="+a+" ,b="+b);
                            System.out.println("和为:"+dd(a,b));
                    }catch(IOException e) {
                            System.out.println("wrong");
                    };是不是要这样写?
    可运行不成功请输入a:4
    请输入b:6
    a=2 ,b=2
    和为:4
    为什么?
      

  7.   

    1要用 bufferdReader
    2 要将类型转化 string 转化成 int
      

  8.   

    public static void main(String[] args)
        {
         try
    {
         int nFirst = 0;
         int nSecond = 0;
         String sFirst,sSecond;
         BufferedReader in = new BufferedReader( new InputStreamReader(System.in) );
         System.out.print("Please input the first number:");
         sFirst = in.readLine();
        
         try
         {
    nFirst = Integer.parseInt( sFirst );
    }
    catch(NumberFormatException nfe )
    {
    System.out.println("错误的参数:"+sFirst);
    System.exit(-1);
    }

    System.out.print("Please input the second number:");
         sSecond = in.readLine();
    try
    {
    nSecond = Integer.parseInt( sSecond );
    }
    catch(NumberFormatException nfe )
    {
    System.out.println("错误的参数:"+sSecond);
    System.exit(-1);
    }
    int nTotal = nFirst + nSecond;
    System.out.println("The added value is:"+ nTotal);
    }

    catch(IOException ie)
    {
    System.out.println( ie );
    }
    }
      

  9.   

    bufferdReader
    是什么?怎么用?
      

  10.   

    感谢大家的帮忙,问题总算解决了。
    谢谢各位!
    代码整理如下:
    import java.io.*;
    import java.io.IOException;
    public class add 
    {
    public static void main(String[] args) 
    {
    System.out.println("Hello World!");
         try
    {
         int nFirst = 0;
         int nSecond = 0;
         String sFirst,sSecond;
         BufferedReader in = new BufferedReader( new InputStreamReader(System.in) );
         System.out.print("Please input the first number:");
         sFirst = in.readLine();
        
         try{
    nFirst = Integer.parseInt( sFirst );
    }
    catch(NumberFormatException nfe )
    {
    System.out.println错误的参数:"+sFirst);
    System.exit(-1);
    }

    System.out.print("Please input the second number:");
         sSecond = in.readLine();
    try{
    nSecond = Integer.parseInt( sSecond );
    }
    catch(NumberFormatException nfe )
    {
    System.out.println错误的参数:"+sSecond);
    System.exit(-1);
    }
    int nTotal = nFirst + nSecond;
    System.out.println("The added value is:"+ nTotal);
    }catch(IOException ie)
    {
    System.out.println( ie );
    }
    }
    }