15.5k views
3 votes
How would you declare an array variable called gross Salary to store 10 values using the double data type?

A) double[] grossSalary = new double[10];
B) double[] grossSalary = {0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0};
C) double[] grossSalary = double[10];
D) double[] grossSalary = [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0];

User Dayquan
by
8.2k points

1 Answer

2 votes

Final answer:

To declare an array of double to store 10 values called grossSalary, the correct declaration is 'double[] grossSalary = new double[10];'.

Step-by-step explanation:

To declare an array variable called grossSalary to store 10 values using the double data type, the correct option is:

A) double[] grossSalary = new double[10];

This line of code initializes an array of doubles with 10 slots, defaulting all values to 0.0 since double types are initialized with 0.0 by default. It is a common way to allocate memory for a fixed size array where the individual elements will be assigned later.

User Jleck
by
7.8k points
Welcome to QAmmunity.org, where you can ask questions and receive answers from other members of our community.