(SOLVED) "Boolean Zen," write an improved version of the following method, which returns whether the given string starts and ends with the same character
Discipline: IT, Web
Type of Paper: Question-Answer
Academic Level: Undergrad. (yrs 3-4)
Paper Format: APA
Pages: 1
Words: 275
Question
BJP5 Self-Check 5.18: startEndSame Language/Type: Java boolean logic method basics Author:
Marty Stepp (on 2019/09/19) Using "Boolean Zen," write an improved
version of the following method, which returns whether the given string
starts and ends with the same character. (In other words, remove
unnecessary logical tests and remove if/else statements that test the
value of a boo lean variable.) Type your solution here: public static
boolean startEndSame(Si) if str. charat str. charat return true; \} else \{ return false; 3
Expert Answer
Answer:
Here is the Java code.
JAVA CODE
public static boolean startEndSame(String str) {
return (str.charAt(0) == str.charAt(str.length() - 1));
}
Yo can run this and try!!
Here, I have removed the if-else statement to return out the Bool value.