The first character in a string is at index 0.
public static String slice(String s) {
int length = s.length();
int mid = (int) (length / 2);
return s.substring(mid);
}
Function Call | Return Value | |||
---|---|---|---|---|
slice("Car") | → | |||
slice("Hello") | → | |||
slice("556843") | → | |||
slice("Elephant") | → | |||
slice("Roses") | → |
Experiment with this code on Gitpod.io