121k views
5 votes
Consider the following code segment, which is intended to display "cat".

String[][] keyboard = {{"q", "W", "e", "r", "t"},
{"a", "S", "d", "f", "g"},
{"z", "X", "C", "v", "b"}};
System.out.println(/* missing expression */);
Which of the following can replace /* missing expression */ so that the code segment works as intended?

User FuzzyDuck
by
4.2k points

2 Answers

1 vote

Answer:

Explanation: can you include a picture?

User Cgogolin
by
3.3k points
4 votes

Answer:

Replace missing expression with:

keyboard[2][2].toLowerCase()+keyboard[1][0]+keyboard[0][4]

Step-by-step explanation:

Given

The above code segment

Required

Which code displays "Cat"

First, we need to identify the location of C, a and t in the array


C \to keyboard[2][2] i.e. C is at the 2nd row index and 2nd column index


a \to keyboard[1][0] i.e. a is at the 1st row index and 0 column index


t \to keyboard[0][4] i.e. t is at the 0 row index and 4th column index

Next convert C to lowercase.

This is done using: toLowerCase() method.

So, we have: keyboard[2][2].toLowerCase()

Next, we concatenate each of the above.

i.e. keyboard[2][2].toLowerCase()+keyboard[1][0]+keyboard[0][4]

Lastly, the statement is printed:

System.out.println(keyboard[2][2].toLowerCase()+keyboard[1][0]+keyboard[0][4]);

User Seanlinsley
by
4.1k points