首先,请原谅我的英语语法,因为我是西班牙语。 好吧,我有这个代码:
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();
来做,但我不知道我应该在括号中输入什么。
答案 0 :(得分: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] + " ");
}
}
}
}
答案 1 :(得分: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] + ", ");
}
}
}
}