我已经用 Java 编写了这段代码,该代码将多个整数作为输入,并在数组中插入整数并打印数组。问题是输出打印全0。
public class Array2 {
private static int i;
private static int[] vett ;
private static int num2;
private static int n;
public static void main(String[] args) throws IOException{
InputStreamReader In = new InputStreamReader(System.in);
BufferedReader myInput = new BufferedReader(In);
String stringa = new String();
String s="";
System.out.println("Enter the number of integers:");
n = Integer.parseInt(myInput.readLine());
vett=new int[n];
for(i=0;i<n;i++){
System.out.println("Insert integer:");
num2 = Integer.parseInt(myInput.readLine());
s=s+vett[i]+" ";
}
System.out.println(s);
}
}
跑:
Enter the number of integers:
2
Insert integer:
1
Insert integer:
2
0 0