Stefanija
Stefanija

Reputation: 1418

Error when entering array from keyboard

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);

    }

}

Upvotes: 0

Views: 45

Answers (1)

ergonaut
ergonaut

Reputation: 7057

You cannot print an array directly, you have to iterate through it's values.

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

Upvotes: 1

Related Questions