import java.util.Scanner;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class StringInteger {
public static void main(String[] args) {
System.out.println("Enter no. of times input numbers will be given : ");
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int index = 0, index1 = 0;
int girl[] = new int[1000];
int boy[] = new int[1000];
for (int i = 1; i <= n; i++) {
String s = sc.next();
Pattern mypattern = Pattern.compile("[0-9]+");
Matcher mymatcher = mypattern.matcher(s);
while (mymatcher.find()) {
if (i % 2 != 0) {
girl[index] = Integer.valueOf(mymatcher.group());
index++;
} else {
boy[index1] = Integer.valueOf(mymatcher.group());
index1++;
}
}
}
for (int j = 0; j < index; j++) {
System.out.print(girl[j] + " ");
}
}
}
Pourquoi la boucle ne fonctionne-t-elle pas jusqu'à sa limite?La boucle java regex ne fonctionne pas correctement
Pouvez-vous ajouter une brève description de ce code est censé faire? –
Aussi ce qu'il fait réellement. – shmosel
* jusqu'à sa limite *? Quelle est la sortie que vous obtenez et quelle est la sortie que vous attendez? – Blasanka