Midfix of 3
The midfix of 3 is the middle 3 characters of a string. Given a String input, output the middle three characters of that string. Assume the word length is always odd and at least three characters.
Hint: Use the String method substring().
Ex: If the input is:
xxxtoyxxx
the output is:
Midfix: toy
code
import java.util.Scanner;
public class Example{
public static void main(String[] args) {
Scanner scnr = new Scanner(System.in);
String str = scnr.nextLine();
int index = (str.length()/2)-1;
System.out.println("Midfix: "+str.substring(index,index+3));
}
}