Concatenate a substring of the original string sentence starting from index 0 and ending before the middle Character(s). Use the substring() method. Use an if statement to account for even or odd, the end index that you need substring()the end index that you need for substring() will be different
public static void main(String[] args) {
String sentence= "Need Help"
String midChars = "";
int sLength = 0;
int midIndex= 0;
char ch1
char ch2
sLength = sentence.length();
if (sLength % 2 != 0) {
midIndex = sLength/2;
ch1 = sentence.charAt(midIndex);
midChars = String.valueOf(ch1);
} else {
ch1 = sentence.charAt(midIndex);
ch2 = sentence.charAt(midIndex-1);
midChars = midChars + String.valueOf(sentence.charAt(midIndex - 1))
+ String.valueOf(sentence.charAt(midIndex));
}
}
System.out.println(????);
// call method called testFirstLast and send String sentence to it as an input
testFirstLast(sentence);