In an array declaration, “size declarator” indicates the number of elements that the array will have.
Hence, the correct answer is option “B”.
Explanation of Solution
Size declarator:
In an array the “size declarator” must be a non-negative integer expression. It may be a variable or a literal value. It is a common practice to use a final variable as a size declarator.
Example:
final int NUM_ELEMENTS = 6;
int[] numbers = new int[NUM_ELEMENTS];
Explanation for wrong answers:
a.Subscript:
A “subscript” is used as an index to pinpoint a specific element within an array.
Hence, the option “A” is wrong.
c.element sum:
The “element sum” is used to add the numbers of element in an array.
Hence, the option “C” is wrong.
d.Reference variable:
The user declare a “reference variable” and use the new keyword to create an instance of the array in memory. The reference variable can be declared as follows:
numbers = new int[6];
Hence, the option “D” is wrong.
Want to see more full solutions like this?
Chapter 7 Solutions
Starting Out with Java: From Control Structures through Data Structures (4th Edition) (What's New in Computer Science)
- Problem Description - JAVA PROGRAMMING Use a Two-dimensional (3x3) array to solve the following problem: Write an application that inputs nine numbers, each of which is between 1 and 10, inclusive. Display the array after the user inputs each value. Rotate/flip the array by changing places. Make the rows columns and vice versa. You have to move the elements to their new locations. Remember to validate the input and display an error message if the user inputs invalid data. Documentation and the screenshot(s) of the results. Example: 1 2 3 4 5 6 7 8 9 the result will be : 1 4 7 2 5 8 3 6 9arrow_forwardWhat is the value that is returned by an array when you use its Length property?arrow_forwardprogramming used: javaarrow_forward
- Movie Data Write a program that will be used to gather statistical data about the number of movies college students see in a month. The program should ask the user how many students were surveyed and dynamically allocate an array of that size. The program then should allow the user to enter the number of movies each student has seen. It should then sort the scores and calculate the average. Modularity: Main: The main function should accept the number of students from the user and dynamically create an array large enough to contain number of movies watched for each student. Input validation: The number of students should be a positive integer. Print the average and free the allocated array when complete. Get the data: This function should get the number of movies watched by each college student. Input validation: The number of movies should be a positive integer. Sort the data: This function should sort the array in ascending order. Note you may use the Standard Template Library sort…arrow_forwardWhat should a programmer be especially aware of when programming with arrays? Syntax errors If-then-else statements Modularization Using an Out of Bounds array subscriptarrow_forwardHomework - identical arrays for one-dimensional: Write a test program which prompts a user to enter the size of two arrays as well as to fill their elements. After that, the program checks the same contents of the elements of the two arrays. If these arrays are equal, the program displays message which is "The two arrays are identical". If not equal, displaying "The two arrays are not identical". Write an equals method that reads two arrays and displays these messages above.arrow_forward
- Data in an array that is only half full might be difficult to keep track of.arrow_forwardAn array can hold as much different data types as you want. True Falsearrow_forwardAn array is a single statement that declares a variable and provides array values as its content. Choose one: a.literal b.builder d.index C.elementarrow_forward
- Which aggregating operations are allowed for struct variables but not array variables, and which are not?arrow_forwardLotto Program C++Write a program that simulates the Powerball lottery. In Powerball, a ticket is comprised of 5 numbers between 1 and 69 that must be unique, and a Powerball number between 1 and 26. The Powerball does not have to be unique. Hint: You can use an array to represent the 5 unique numbers between 1 and 69, and an integer variable to represent the powerball. The program asks the player if they'd like to select numbers or do a 'quickpick', where the numbers are randomly generated for them. If they opt to select numbers, prompt them to type the numbers in and validate that they are unique (except the powerball), and in the correct range. The program then generates a 'drawing' of 5 unique numbers and a Powerball, and checks it against the user's lotto ticket. It assigns winnings accordingly. Because it is so rare to win the lottery, I suggest hard coding or printing values to when testing the part of the program that assigns winnings.arrow_forward
- EBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENTProgramming Logic & Design ComprehensiveComputer ScienceISBN:9781337669405Author:FARRELLPublisher:CengageMicrosoft Visual C#Computer ScienceISBN:9781337102100Author:Joyce, Farrell.Publisher:Cengage Learning,