Réponse acceptée !
Salut,
voici ce que tu peux faire avec le jdk<= 1.4
public class Read {
public static String getLine() { // Lire un String
String tmp = "";
char c = '\0';
try {
while ( (c = (char) System.in.read()) != '\n') {
if (c!= '\r') tmp = tmp + c;
}
}
catch (IOException e) {
return "\n";
}
return tmp;
}
public static byte getByte() {
byte x = 0;
try {
x = Byte.parseByte(getLine());
} catch (NumberFormatException e) {
return -1;
}
return x;
}
public static short getShort() {
short x = 0;
try {
x = Short.parseShort(getLine());
}
catch (NumberFormatException e) {
return -1;
}
return x;
}
public static int getInt() {
int x = 0;
try {
x = Integer.parseInt(getLine());
}
catch (NumberFormatException e) {
return -1;
}
return x;
}
public static long getLong() {
long x = 0;
try {
x = Integer.parseInt(getLine());
}
catch (NumberFormatException e) {
return -1;
}
return x;
}
public static double getDouble() {
double x = 0.0;
try {
x = Double.valueOf(getLine()).doubleValue();
}
catch (NumberFormatException e) {
return -1;
}
return x;
}
public static float getFloat() {
float x = 0.0f;
try {
x = Double.valueOf(getLine()).floatValue();
}
catch (NumberFormatException e) {
return -1;
}
return x;
}
public static char getChar() {
String tmp = getLine();
if (tmp.length() == 0)
return '\n';
else {
return tmp.charAt(0);
}
}
}
et la si tu es avec le un jdk >= 1.5 alors la c'est le bonheur tu peux utiliser l'objet
Scanner avec le quel tu peux lire fichier, clavier, socket, bref tout type d'inputstream.
Pour info tu as printf en java depuis le jdk 1.5
------------------------------------
"On n'est pas au resto : ici on ne fait pas dans les plats tout cuits ..."
WORA