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));
4 Answers
0
I believe it's looking for the output, which is TEA.
0
Really? How? Please explain more @Joshua
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.
0
@Joshua Thanks for the explanation!