Following are the test cases
Test cases | Result | Status |
---|---|---|
firstHalf(HelloThere) | Hello | OK |
firstHalf(abcdef) | abc | OK |
firstHalf(Word) | Wo | OK |
Java solution
package test;
public class Program13 {
public static void main(String[] args) {
Program13.firstHalf("HelloThere");
Program13.firstHalf("abcdef");
Program13.firstHalf("Word");
}
public static String firstHalf(String str) {
return str.substring(0, str.length() / 2);
}
}
Javascript solution
const firstHalf = (str) => {
return str.substr(0, str.length/2);
}
console.log(firstHalf("HelloThere")); //Hello
console.log(firstHalf("abcdef")); //abc
console.log(firstHalf("Word")); //Wo