import java.io.*;
public class OutilsES {
public static String lireLigne () {
InputStreamReader lecteurFlot = new InputStreamReader (System.in);
BufferedReader lecteurTampon = new BufferedReader (lecteurFlot);
String data = "";
try {
data = lecteurTampon.readLine ();
} catch (IOException ioe) {
}
return data;
}
public static int lireEntier () {
int val = 0;
boolean complété = false;
while (!complété) {
String s = lireLigne ();
try {
val = Integer.parseInt (s);
complété = true;
} catch (NumberFormatException nfe) {
System.err.println (s + " n'est pas un entier valide");
}
}
return val;
}
public static float lireRéel () {
float val = 0.0f;
boolean complété = false;
while (!complété) {
String s = lireLigne ();
try {
val = Float.parseFloat (s);
complété = true;
} catch (NumberFormatException nfe) {
System.err.println (s + " n'est pas un réel valide");
}
}
return val;
}
public static void main (String [] args) {
System.out.println ("Entrez une ligne de texte ...");
String ligne = lireLigne ();
System.out.println ("Vous avez entré: \"" + ligne + "\"");
System.out.println ("Entrez un entier...");
int entier = lireEntier ();
System.out.println ("Votre choix: " + entier);
System.out.println ("Entrez un réel...");
float réel = lireRéel ();
System.out.println ("Votre choix: " + réel);
}
}
Le code source de la petite classe OutilsES mise à votre disposition par votre chic professeur est tel que proposé à droite. Bon, ce n'est pas du grand art, mais ça dépanne.