user3443171
user3443171

Reputation: 3

I am getting an error about "is of '.class' expected." and I don't understand why.

The error that i am getting is of '.class' expected. All i want to do is to get the values of the array from the user. Kindly help me out.

int[] array = new int [10];
Scanner input=new Scanner (System.in);

// The error comes from the next line.
int array = input.nextInt[];

System.out.println("1. Find Mean");
System.out.println("2. Change Number");
System.out.println("1. Print All");
System.out.println("1. Exit");

Upvotes: 0

Views: 37

Answers (2)

Elliott Frisch
Elliott Frisch

Reputation: 201447

You already have a variable named array.

int[] array = new int [10]; // <-- right there.
int count = 0; // <-- add this.
Scanner input=new Scanner (System.in);
array[count++] = input.nextInt(); // <-- parens for a method call, 
      // square brackets for the array, and add one to the count.

Upvotes: 2

rgettman
rgettman

Reputation: 178263

Use parentheses () for a method call with no parameters, not brackets [].

int array = input.nextInt();

Upvotes: 1

Related Questions