我用BufferedReader的ready()方法判断搞定的 public class Main { private static String regex = "\\s"; public static void main(String[] args) throws IOException { Set<String> set = new HashSet<String>(); BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); for (int i = 0; i < 50; i++) { if (in.ready()) { String text = in.readLine(); String[] arr = text.split(regex); for (String val : arr) { set.add(val); } } else { break; } } System.out.println(set.size()); in.close(); } }
点赞 评论

相关推荐

01-30 16:13
浙江大学 Java
点赞 评论 收藏
分享
牛客网
牛客网在线编程
牛客网题解
牛客企业服务