Question
(InJava) Using Boolean Zen, write an improved (simplified) version of the following method, which returns whether the given String starts and ends with the same
(InJava) Using "Boolean Zen," write an improved (simplified) version of the following method, which returns whether the given String starts and ends with the same character: (2-credit)
public static boolean startEndSame(String str) {
if (str.charAt(0) == str.charAt(str.length()-1)) {
return true;
} else {
return false;
}
} // end of startEndSame()
To submit, write a class, TestWords, which contains main() and startEndSame(). The main() method should call startEndSame() method as follows:
within main(),
System.out.println("\"pop\" returns " + startEndSame("pop"));
System.out.println("\"top\" returns " + startEndSame("top"));
System.out.println("\"erase\" returns " + startEndSame("erase"));
System.out.println("\"stars\" returns " + startEndSame("stars"));
... // test the method with any other words...
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started