1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
| import java.io.*;
public class Lire {
public static int entier(String message) {
String s = null;
int n;
int ok;
do {
ok = 0;
System.out.println(message);
try {
s = new DataInputStream(System.in).readLine();
} catch (IOException e) {
System.out.println("Lecture au clavier impossible.");
}
if (s == null)
return 0;
else {
try {
n = Integer.valueOf(s).intValue();
ok = 1;
} catch (NumberFormatException e) {
n = 0;
ok = 0;
System.out.println("Ce nest pas un nombre entier.");
}
}
} while (ok != 1);
return n;
}
} |