Which of the following are valid declarations? Which instantiate an array object? Explain your answers.

a. int primes = {2, 3, 4, 5, 7, 11};
b. float elapsedTimes[] = {11.47, 12.04, 11.72, 13.88};
c. int[] scores = int[30];
d. int[] primes = new {2,3,5,7,11};
e. int[] scores = new int[30];
f. char grades[] = {'a', 'b', 'c', 'd', 'f'};
g. char[] grades = new char[];


a. Invalid; an int cannot be declared and initialized using an intializer list. The brackets are missing.
b. Valid; the brackets can be placed either after the element type or after the reference variable. However, this is not the preferred technique. This declaration creates an array object.
c. Invalid; the right hand side of the assignment operator must contain either an initializer list or a new operation.
d. Invalid; “new” on the right hand side of the assignment operator is neither necessary nor acceptable.
e. Valid; the assignment is correct Java syntax. This declaration creates an array object.
f. Valid; the brackets can be placed either after the element type or after the reference variab=le. However, this is not the preferred technique. This declaration creates an array object.
g. Invalid; the size of the array must be indicated when the array is instantiated.

Computer Science & Information Technology

You might also like to view...

A Python program consists of a series of ____.

A. recipes B. graphics C. instructions D. vectors

Computer Science & Information Technology

What arithmetic operations are on the same level of precedence as multiplication? ________ .

Fill in the blank(s) with the appropriate word(s).

Computer Science & Information Technology

Identify an accurate statement about creating a form in Microsoft Access 2016??

A. ?Tables and queries cannot perform any of the functions performed by a form. B. ?You cannot use Layout view to make changes to a form. C. ?When you first create a form, it opens in Layout view. D. ?In a simple form, all the fields and records in a table are displayed at once.

Computer Science & Information Technology

The control that receives the focus the first time Tab is pressed has a TabIndex property set to ________.

a) First b) 0 c) Next d) 1

Computer Science & Information Technology