Notice substr() can also be called with a single argument.
public static String slice(String s) {
String c = s.substring(s.length() - 1);
return c;
}
Function Call | Return Value | |||
---|---|---|---|---|
slice("Car") | → | |||
slice("Truck") | → | |||
slice("55684") | → | |||
slice("Elephant") | → | |||
slice("Roses") | → |
Experiment with this code on Gitpod.io