Comment optimiser EntreeClavier.java

Résolu
Arnold59 Messages postés 27 Date d'inscription lundi 8 mars 2004 Statut Membre Dernière intervention 15 avril 2019 - 30 nov. 2005 à 16:07
Arnold59 Messages postés 27 Date d'inscription lundi 8 mars 2004 Statut Membre Dernière intervention 15 avril 2019 - 30 nov. 2005 à 17:11
Bonjour,

********************************************************
* Programme : EntreeClavier.java
* Version java : Jdk 1.3 - Jdk 1.5_5 *
* Systeme d'exploitation: Windows 98SE, XP Pro, Linux *
********************************************************/

import java.io.*;

public class EntreeClavier{

public static int readInt(){
boolean flag = false;
int i = -1;
while(!flag){
String s = "";
try{
char c;
for(c = (char)System.in.read(); c != '\n' && c != '\r'; c = (char)System.in.read())
s = s + c;
if(c == '\r')
c = (char)System.in.read();
i = Integer.parseInt(s);
flag = true;
}
catch(IOException ioexception){
System.out.println("Erreur");
}
catch(NumberFormatException numberformatexception){
System.out.println("Erreur enter un nombre");
}
}
return i;
}

public static int readInt(String s){
System.out.print(s);
return readInt();
}

public static float readFloat(){
boolean flag = false;
float f = 0.0F;
while(!flag){
String s = "";
try{
char c;
for(c = (char)System.in.read(); c != '\n' && c != '\r'; c = (char)System.in.read())
s = s + c;

if(c == '\r')
c = (char)System.in.read();
f = Float.parseFloat(s);
flag = true;
}
catch(IOException ioexception){
System.out.println("Erreur");
}
catch(NumberFormatException numberformatexception){
System.out.println("Erreur entez un nombre");
}
}
return f;
}

public static float readFloat(String s){
System.out.print(s);
return readFloat();
}

public static double readDouble(){
boolean flag = false;
double d = 0.0D;
while(!flag){
String s = "";
try{
char c;
for(c = (char)System.in.read(); c != '\n' && c != '\r'; c = (char)System.in.read())
s = s + c;

if(c == '\r')
c = (char)System.in.read();
d = Float.parseFloat(s);
flag = true;
}
catch(IOException ioexception){
System.out.println("Erreur");
}
catch(NumberFormatException numberformatexception){
System.out.println("Erreur entez un nombre");
}
}
return d;
}

public static double readDouble(String s){
System.out.print(s);
return readDouble();
}

public static char readChar(){
char c = ' ';
try{
char c1 = (char)System.in.read();
c = c1;
for(; c1 != '\n' && c1 != '\r'; c1 = (char)System.in.read());
if(c1 == '\r')
c1 = (char)System.in.read();
}
catch(IOException ioexception){
System.out.println("Erreur");
}
return c;
}

public static char readChar(String s){
System.out.print(s);
return readChar();
}

public static String readString(){
String s = "";
try{
char c;
for(c = (char)System.in.read(); c != '\n' && c != '\r'; c = (char)System.in.read())
s = s + c;

if(c == '\r')
c = (char)System.in.read();
}
catch(IOException ioexception){
System.out.println("Erreur");
}
return s;
}

public static String readString(String s){
System.out.print(s);
return readString();
}

public static void attente(){
try {
System.in.read();
}
catch(IOException ioexception) {
}
}
}

2 réponses

Arnold59 Messages postés 27 Date d'inscription lundi 8 mars 2004 Statut Membre Dernière intervention 15 avril 2019
30 nov. 2005 à 17:11
Comment optimiser ce code pour qu'il soit compatible avec les nouvelles instaructions JDK1.5 ?

De plus, je rencontre des pb de compilation avec des programmes "anciens" conçus sous jdk1.3 => Erreur sous jdk1.5
3
luuuuudooooo Messages postés 64 Date d'inscription mardi 4 octobre 2005 Statut Membre Dernière intervention 2 août 2006 4
30 nov. 2005 à 16:54
Bonjour,

Quelle est ta question?
0
Rejoignez-nous