输入:
①adfasjdoiasldhlfa
②a
③aa
④abcd
输出:
①fasjdoiasldhlf
②a
③aa
④a
import java.util.Scanner;
public class Main {public static void main(String[] args) {Scanner scanner = new Scanner(System.in);String str = scanner.next();String subStr = "";for (int i = 0; i < str.length(); i++) {String newSubStr = str.charAt(i) + "";for (int j = i+1; j < str.length(); j++) {if (j == str.length() - 1 && str.charAt(i) != str.charAt(j)){newSubStr = str.charAt(i) + "";break;}if (str.charAt(i) == str.charAt(j)){newSubStr = str.substring(i,j+1);break;}newSubStr = str.substring(i,j+1);}if (newSubStr.length() > subStr.length()){subStr = newSubStr;}}System.out.println(subStr);}
}