Set 轻松解决
import java.util.*; public class Main { public Main() { } public boolean isAllCharExist(String pShortString, String pLongString) { Set<Character> set = new HashSet<>(); for (char ch : pLongString.toCharArray()) { set.add(ch); } for (char ch : pShortString.toCharArray()) { if (!set.contains(ch)) { return false; } } return true; } public static void main(String[] args) { Main solution = new Main(); Scanner in = new Scanner(System.in); while (in.hasNextLine()) { String pShortString = in.nextLine(); String pLongString = in.nextLine(); boolean res = solution.isAllCharExist(pShortString, pLongString); System.out.println(res); } } }