-5

文字列から整数値を抽出する必要があります。

例えば

this is the java 1234 and 7899/45767 program

のような整数のみを抽出する必要があるという点で

1234
7899
45767
4

3 に答える 3

0

これを試して

    Matcher m = Pattern.compile("-?\\d+").matcher(str);
    while(m.find()) {
        System.out.println(m.group());
    }
于 2013-08-01T11:55:46.140 に答える
0

Scanner.nextInt()メソッド を試すことができます

Scanner sc = new Scanner("this is the java 1234 and 7899/45767 program, in that i need to extract only integer like 1234 7899 45767");
while(sc.hasNext()) {
   boolean scanned = false;
   if(sc.hasNextInt()) {
      System.out.println(sc.nextInt());
      scanned = true;
   }
   if(!scanned)
     sc.next();
}
于 2013-08-01T11:50:59.377 に答える