Computer Science, asked by ramasareverma99, 8 months ago

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.​

Answers

Answered by Oreki
2

I. name[0] = 'D';

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

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

name[i] = " ";

}

OR

java.util.Arrays.fill(name, " ");

Answered by anindyaadhikari13
2

\star\:\:\:\sf\large\underline\blue{Answer:-}

Given declarations,

final int SIZE = 20;

char[] name = new char[SIZE];

Number 1

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

The statement is:-

name[0]= 'D';

First index is 0 so we assign 'D' to 0th position in name array.

Number 2

  • Write the output statement that prints the value of the tenth element of the array.

10 element index is 9.

So, the print statement will be

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

Number 3

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

The statement should look something like this.

for(int i=0;i<10;i++)

name[i]=' ';

Similar questions