怎样输入?

在Eclipse上输入数据,但是怎么都不对,求大神指教:
package daoTest;

import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {

public static void main(String[] args){
    try{

    BufferedReader geta = new BufferedReader(new InputStreamReader(System.in));

    int a[] = new int[6];
    System.out.print(a.length);
    for(int i = 0; i < a.length; i++){
        a[i] = geta.read();
    }
    for(int j = 0; j < a.length; j++)
        System.out.println(a[j]);

}catch (Exception e) {
    e.printStackTrace();
}

}

}
输入数据时怎么样按回车输入一个完整的数(比如说40,现在它只会4和0分别作为2个数来读取)。。。
另外怎样让它按输入输出结果,不要输出ASCII码。。。

这是完整程序:
[code="java"]

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Formal {
public static void main(String[] args) throws NumberFormatException, IOException {
int a[] = new int[6];
BufferedReader geta = new BufferedReader(new InputStreamReader(System.in));
for (int i = 0; i < a.length; i++) {
try {
a[i] = Integer.parseInt(geta.readLine());
} catch (NumberFormatException e) {
i--;
System.out.println("请输入整数!");
}
}
}
}
[/code]

[quote]
for(int i = 0; i < a.length; i++){
a[i] = geta.read();
}
[/quote]
是不是这个地方有问题?

直接String str = geta.readLine();

你需要用回车做一次输入的话,那就使用readline。

同上!
[code="java"]
public class Main {

public static void main(String[] args) {
    try {
        BufferedReader geta = new BufferedReader(new InputStreamReader(System.in));
        int a[] = new int[6];
        System.out.print(a.length);
        for (int i = 0; i < a.length; i++) {
            a[i] = Integer.parseInt(geta.readLine());
        }
        for (int j = 0; j < a.length; j++)
            System.out.println(a[j]);

    } catch (Exception e) {
        e.printStackTrace();
    }

}

}
[/code]

[quote]
想请教下为什么int类型不行呢。。。
在上面我是定义一个int类型数组,怎样读入输出???
[/quote]
read返回int不是说返回输入的整数,而是返回输入的第一个字符的整数表示,你输入个字母也能返回的.

不会吧,我的正确的啊!我输入1 2 3 4 5 6能得到结果(空格代表回车)

你输入的不是整数,所以 Integer.parseInt报错,类型无法转换

[code="java"]
for (int i = 0; i < a.length; i++) {
try {
a[i] = Integer.parseInt(geta.readLine());
} catch (NumberFormatException e) {
i--;
System.out.println("请输入整数!");
}
}

[/code]

如果想只允许输入整数,那就用try catch在:
a[i] = Integer.parseInt(geta.readLine());

如果转换出错,就是输入了其他字符,就提示出错信息,再重新读,一直读到你的数组满了为止。

用a[i] = Integer.parseInt(geta.readLine());就行。输入的是整数就能转化成整数,其他的会报错,可以用try-catch来提示
try{
a[i] = Integer.parseInt(geta.readLine());
}catch(Exception e){System.out.println("请输入整数!");}

[quote]
怎么可能。。。我输得都是1~9中随便抽的6个数。。。
而且不是输出有问题,而是代码本身就出错了,无法编译。。
[/quote]

那断代码没有问题,我原封不动的复制下来,正确编译,运行了.

你顶上的3个包导了吗:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

[quote]
a[i] = geta.readLine();
// a[i] = Integer.parseInt(geta.read());
[/quote]

a[i] = Integer.parseInt(geta.readLine());