我已經用Java編寫了這個代碼,它接受一些整數並在數組中插入整數並打印數組。問題是,輸出打印所有0如何在java中打印數組?
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