题解 | #字符串字符匹配#
字符串字符匹配
https://www.nowcoder.com/practice/22fdeb9610ef426f9505e3ab60164c93
import java.util.Scanner; // 注意类名必须为 Main, 不要有任何 package xxx 信息 public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); String str1 = in.nextLine(); String str2 = in.nextLine(); int flag = 0; // 遍历所有字符 for (int i = 0; i < str1.length(); i++) { flag = 0; //判断是否出现过 for (int j = 0; j < str2.length(); j++) { if (str1.charAt(i) == str2.charAt(j)) { flag = 1; break; } } if (flag == 0) { System.out.print("false"); return; } } if (flag == 1) { System.out.print("true"); } } }