校招笔试题编程技巧总结
技巧一://统计字符串s1的频率
String s1 = in.nextLine(); //统计字符串s1的频率 for (char c1 : s1.toCharArray()) { if (hashMap1.containsKey(c1)) { hashMap1.put(c1, hashMap1.get(c1) + 1); } else { hashMap1.put(c1, 1); } }
技巧二:输入判断加 hasNext()
Scanner scan=new Scanner(System.in); while(scan.hasNext()){ String str1=scan.nextLine(); String str2=scan.nextLine(); boolean result=isContain(str1,str2); if(result){ System.out.println("Yes"); }else{ System.out.println("No"); } } scan.close();