-3

首先,由于我是西班牙人,请原谅我的英语语法。好吧,我有这个代码:

public class practica {
    public static void main(String[] args) {

        Scanner consola = new Scanner(System.in);
        int numero = consola.nextInt();
        if (numero > 0 && numero <= 100) {
            int vector[] = new int[numero];

            for (int y = 0; y < numero; y++) {
                vector[y] = consola.nextInt();
            }
        }
    }
}

在我(通过控制台)读取数字后,我必须只在一行中显示它们。我知道我必须这样做,System.out.print();但我不知道我应该在括号中输入什么。

4

2 回答 2

0
public class practica {
  public static void main(String[] args) {

    Scanner consola = new Scanner(System.in);
    int numero = consola.nextInt();
    if (numero > 0 && numero <= 100) {
        int[] vector = new int[numero];

        for (int y = 0; y < numero; y++) {
            vector[y] = consola.nextInt();
        }

        //look here
        for(int i = 0; i < vector.length; i++){
            System.out.print(vector[i] + ", ");
       }
    }
  }

}

于 2013-04-02T09:46:55.957 回答
0

使用此代码:

public class practica {
    public static void main(String[] args) {

        Scanner consola = new Scanner(System.in);
        int numero = consola.nextInt();
        if (numero > 0 && numero <= 100) {
            List<Integer> vector = new ArrayList<>();

            for (int y = 0; y < numero; y++) {
                vector.add(consola.nextInt());  
            }
            System.out.println(vector);
        }
    }
}

或这个 :

public class practica {
    public static void main(String[] args) {

        Scanner consola = new Scanner(System.in);
        int numero = consola.nextInt();
        if (numero > 0 && numero <= 100) {
            int vector[] = new int[numero];

            for (int y = 0; y < numero; y++) {
                vector[y] = consola.nextInt();  
                System.out.print(vector[y] + " ");
            }
        }
    }
}
于 2013-04-02T09:46:25.273 回答