Who can help explain the solution to me please. What is it that needs to be done. | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Who can help explain the solution to me please. What is it that needs to be done.

Given the following three Strings: String a = "This is a String."; String b = "This is another String."; String c = "Another String this is."; if (b.length() > c.length()) { System.out.println(b); } else if (c.length() > b.length()) { System.out.println(c); } else { System.out.println(b.charAt(0) + "E" + c.charAt(0));

23rd Feb 2017, 11:05 AM
Ukemeobong Akpan
4 Answers
0
I believe it's looking for the output, which is TEA.
23rd Feb 2017, 11:12 AM
Division by Zero
0
Really? How? Please explain more @Joshua
23rd Feb 2017, 11:14 AM
Ukemeobong Akpan
0
The length function gets the length of the string. Strings b and c are equal in length, so the first two if conditions fail. b is not longer than c, and c is not longer than b. They are equal. Therefore, the else block is executed. chatAt outputs the character at that index. So charAt (0) would output the first character at the zeroith index. So we have the following. charAt (0) on b which is T E charAt (0) on c which is A So the result is TEA.
23rd Feb 2017, 11:20 AM
Division by Zero
0
@Joshua Thanks for the explanation!
23rd Feb 2017, 12:29 PM
Ukemeobong Akpan