ICSE Class 10 Computer Applications Question 12 of 59

Arrays — Question 14

Back to all questions
14
Question

Question 14

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.

Answer

i. name[0] = 'D';

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

iii. For Statement:

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