递归实现字符或单词在字符串中是否存在
import java.util.*; public class Dictionary { static String dictionary = new String("abskljlsajdfklajflkdhalkldfjalhflas"); public static void main(String []args){ Scanner in = new Scanner(System.in); String input = in.nextLine().trim(); System.out.println(indexSearch(input)); } static boolean indexSearch(String str){ boolean flag = true ; if(str.length()>dictionary.length()){ return false; } for(int i = 0 ;i < str.length() ;i++){ if(str.charAt(i)!= dictionary.charAt(i)){ flag = false ; break; } } if (flag == true){ return true; } else{ dictionary = dictionary.substring(1,dictionary.length()); System.out.println(dictionary); return indexSearch(str); } } }