I want to remove the last 3 characters of the string if the string has the same prefix and suffix. eg: the string is "systemsys"
, it should print system
. Few inputs I am trying : incgoogleinc
. Not working for this input
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
String str = s.nextLine();
if(str.length() > 3) {
if (str.startsWith(str.substring(0, 3)) == (str.substring(str.length()-3, str.length()-1))) {
System.out.println(str.substring(0, str.length()-3));
} else {
System.out.println(str);
}}}
Not working for different inputs : mictestingmic
, comwebsitecom