文字列から整数値を抽出する必要があります。
例えば
this is the java 1234 and 7899/45767 program
のような整数のみを抽出する必要があるという点で
1234
7899
45767
文字列から整数値を抽出する必要があります。
例えば
this is the java 1234 and 7899/45767 program
のような整数のみを抽出する必要があるという点で
1234
7899
45767
これを試して
Matcher m = Pattern.compile("-?\\d+").matcher(str);
while(m.find()) {
System.out.println(m.group());
}
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();
}