我使用的解决方案如下所示:
Pattern numberPat = Pattern.compile("\d+");Matcher matcher1 = numberPat.matcher(line);Pattern stringPat = Pattern.compile("What is the square of", Pattern.CASE_INSENSITIVE);Matcher matcher2 = stringPat.matcher(line);if (matcher1.find() && matcher2.find()){ int number = Integer.parseInt(matcher1.group()); pw.println(number + " squared = " + (number * number));}
我确信这不是一个完美的解决方案,但它满足了我的需求。谢谢大家的帮助。:)
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)