2015-09-27 86 views
0
package array; 

import java.util.Scanner; 

public class Array { 

    public static void main(String[] args) { 
     int n; 
     Scanner input = new Scanner(System.in); 
     n = input.nextInt(); 
     int[] a = new int[n]; 
     for (int i = 0; i < n; i++) { 
      a[i] = input.nextInt(); 
     } 

     System.out.println(a); 

    } 

} 
+0

和它是什麼錯誤..? – ergonaut

+0

n = 5 a = {3 4 6 7 9}在屏幕上:[I @ 647e05 – Merian

+0

@ IQ246這不是錯誤它打印數組'Object' –

回答

1

您不能直接打印數組,您必須遍歷它的值。

for (int j=0;j<a.length;j++){ 
    System.out.println(a[j]); 
}