输入两个字符,按回车就结束了,读入的是ASCII码

解决方案 »

  1.   

       char a,b;
       a=(char)System.in.read();
       b=(char)System.in.read();
       
       System.out.println("a="+a+","+"b="+b);
    楼主不管输入多少字符,只读取前两个
    按回车就结束了.如果想读入字符窜的话
    public static String getString() {//use static make a class method to read
    // a
    // Sring from kedboard String input = "";
    BufferedReader stdin = new BufferedReader(new InputStreamReader(
    System.in)); try {
    input = stdin.readLine();
    } catch (IOException iox) {
    System.err.println(iox);
    }
    return input;
    }
      

  2.   

    我是想就像C语言如:for(i=0;i<4;i++)
                           scanf("%d",&a[i]);
    这样连续的输入值实在是不理解JAVA是如何做的