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

1. Write the declaration and initialization of a char array with 12 elements ini

ID: 3543706 • Letter: 1

Question

1. Write the declaration and initialization of a char array with 12 elements initialized to '$'. Use the most

appropriate loop.


2. Given


char[] letters= { 'a', 'b', 'c', 'd', 'e' };


what is the value of letters[3]?


3. Write a declaration for an integer array that holds 10 elements and initialize the second element to

the number 5.


4. What is the value of the 5th element of array after the following code segment executes?


int[] array = new int[17];

for(int i = 2; i<= 16; i++)

{

if(i%2 == 0)

array[i] = 2;

else

array[i] = 1;

}

Explanation / Answer

1.

char a[]= new char('$');


2. 'd'


3. int[] a = new int(10);

a[1]=5


4.

2