Bonjour,

J'ai un problème en JAVA pour transformer une String en entier (int).

J'ai écris le code suivant :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
import java.util.regex.Matcher;
import java.util.regex.Pattern;
 
public class OSE {
	public static void main(String args[]) {
		String secu="12121212121212 4";
		secu=secu.replaceAll(" ", "");
		Pattern psecu = Pattern.compile("[0-9]{15}");
		Matcher msecu = psecu.matcher(secu);
		boolean bsecu = msecu.matches();
		if (!bsecu){
			System.out.println("Le numero de securite social doit comporter quinze chiffres.");
		} 
		else{
			int i=Integer.valueOf(secu).intValue();
 
		}
	}
}
J'obtiens le message d'erreur :
Exception in thread "main" java.lang.NumberFormatException: For input string: "121212121212124"
at java.lang.NumberFormatException.forInputString(Unknown Source)
at java.lang.Integer.parseInt(Unknown Source)
at java.lang.Integer.valueOf(Unknown Source)
at OSE.main(OSE.java:15)
Je ne vois pas ce qui ne lui convient pas. Pouvez vous m'aider ?

Maxime