Computer Applications

Given the following declarations:

final int SIZE = 20;
char[] name = new char[SIZE];

i. Write an assignment statement that stores 'D' into the first element of the array name.

ii. Write an output statement that prints the value of the tenth element of the array name.

iii. Write a for statement that fills the array name with spaces.

Java Arrays

10 Likes

Answer

i. name[0] = 'D';

ii. System.out.println(name[9]);

iii. For Statement:

for (int i = 0; i < SIZE; i++) {
    name[i] = ' ';
}

Answered By

7 Likes


Related Questions