Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

JAVA PROGRAMING BEGIN Please interlace your answers with a copy of the questions

ID: 3755072 • Letter: J

Question

JAVA PROGRAMING BEGIN

Please interlace your answers with a copy of the questions, and make your text black. Easy peasy.

1. Look at the following array definition.
int[] values = new int[9];
A) How many elements does the array have?
B) What is the subscript of the first element in the array?
C) What is the subscript of the last element in the array?
D) If an int uses four bytes of memory, how much memory does the array use?

2. The arrays array1 and array2 each hold 25 integer elements. Write code that copies
the values in array1 to array2.

3. In a program you need to store the identification numbers of 11 employees (as ints)
and their weekly gross pay (as doubles).
A) Define two arrays that may be used in parallel to store the 11 employee
identification numbers and 11 weekly gross pay amounts.
B) Write a loop that uses these arrays to print each employee’s identification number
and weekly gross pay.

Explanation / Answer

1. Look at the following array definition.
int[] values = new int[9];
A) How many elements does the array have?

Answer : 9


B) What is the subscript of the first element in the array?

Answer : values[0]


C) What is the subscript of the last element in the array?

Answer : values[8]


D) If an int uses four bytes of memory, how much memory does the array use?

Answer : 36

4 * 9 = 36

2. The arrays array1 and array2 each hold 25 integer elements. Write code that copies
the values in array1 to array2.

Answer:

for(int i = 0 ; i < array1.length;i++){

array2[i] = array1[i];

}

3. In a program you need to store the identification numbers of 11 employees (as ints)
and their weekly gross pay (as doubles).
A) Define two arrays that may be used in parallel to store the 11 employee
identification numbers and 11 weekly gross pay amounts.

Answer :

int[] e_id = new int[11];

double[] e_grossPay = new double[11];


B) Write a loop that uses these arrays to print each employee’s identification number
and weekly gross pay.

Answer :

for(int i = 0 ; i < e_id.length;i++){

System.out.println(e_id[i]);

System.out.println(e_grossPay[i]);

}