Print Sentences as Table
Complete the function below. The function receives the full standard input as a single string and must return the exact standard output lines for the described problem.
You are given n sentences and a fixed table content width width. Print each sentence as one row in a bordered table.
Input
The first line contains two integers n and width. The next n lines each contain one sentence. Sentences may contain spaces, and each sentence length is guaranteed to be at most width.
Output
For each of the n sentences, output rows in the following pattern: before each sentence row output a border line, and after the last sentence row output one final border line, for a total of n+1 border lines interleaved with n sentence rows (if n > 0).
- A border line is
+, followed by exactlywidth + 2dash (-) characters, followed by+. - A sentence row is
|, followed by one space, followed by the sentence, followed by enough trailing spaces so that the sentence plus all trailing spaces together equal exactlywidthcharacters, followed by one space, followed by|. The total number of characters between the two|characters is thuswidth + 2.
If n = 0, return no output lines.
Complete solvePrintSentencesAsTable. It has one parameter, String input, containing the full stdin payload. Return the stdout payload as an array of lines, without trailing newline characters.
input = "3 55\nHello world\nHow are you today\nBye" return = ["+---------------------------------------------------------+", "| Hello world |", "+---------------------------------------------------------+", "| How are you today |", "+---------------------------------------------------------+", "| Bye |", "+---------------------------------------------------------+"]
0 <= n <= 10^51 <= width <= 10^4- Each sentence contains printable ASCII characters and spaces.
- Each sentence length is at most
width.
public String[] solvePrintSentencesAsTable(String input) {
// write your code here
}