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
Get step-by-step solutions from verified subject matter experts
