public static void main(String[] args) { // TODO Auto-generated method stub String input = "1 fish 2 fish red fish blue fish"; Scanner s = new Scanner(input); s.findInLine("(\\d+) fish (\\d+) fish (\\w+) fish (\\w+)"); MatchResult result = s.match(); for (int i=1; i<=result.groupCount(); i++) System.out.println(result.group(i)); s.close(); }我这里没有问题啊,lz检查下
比如
public GetNumber()
{
Scanner sr = new Scanner("p");
}
应该这样定义吧
Scanner sr = new Scanner("System.in");
然后可以这样读如数据:
String str = sr.next();
// TODO Auto-generated method stub
String input = "1 fish 2 fish red fish blue fish";
Scanner s = new Scanner(input);
s.findInLine("(\\d+) fish (\\d+) fish (\\w+) fish (\\w+)");
MatchResult result = s.match();
for (int i=1; i<=result.groupCount(); i++)
System.out.println(result.group(i));
s.close();
}我这里没有问题啊,lz检查下