public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println(
"Bonjoir lol \n Convertire de Celsius à Fahrenheit tape 1 \n Convertire de Fahrenheit à Celsius tape 2 ");
//si on ecrit rien apres 5 sc lapp doit se fermer
Timer tm =new Timer () ;
tm.schedule(new TimerTask() {
int tim =5;
@Override
public void run() {
tim--;
System.out.println(tim);
if (tim==0) { tm.cancel();
System.exit(0);
}
}
}, 1000, 1000);
int choix;
try {
choix = sc.nextInt();
} catch (java.util.InputMismatchException e) {
System.out.println("Caractere non numerique § erreur ");
choix = sc.nextInt();
}
System.out.println("D'accord");
if (choix != 1 | choix != 2) {
while (choix != 1 && choix != 2) {
System.out.println("Reassayez , tapez soit 1 soit 2 !!!!!");
try {
choix = sc.nextInt();
} catch (java.util.InputMismatchException e) {
System.out.println("Caractere non numerique 1 ou 2");
choix = sc.nextInt();
}
}
}
if (choix == 1) {
System.out.println("Entrez la temperature en Celsius ");
int tempc = sc.nextInt();
System.out.println(celtofar(tempc) + " F°");
} else if (choix == 2) {
System.out.println("Entrez la temperature en Fahrenheit ");
int tempf = sc.nextInt();
System.out.println(fartocel(tempf) + "C°");
sc.close();
}
}
}
Hello , I used a chronometer when Tim=0 ,it exits the program.But how can I make the chronometer reset every time I type something in my keyboard ?? Hope someone can help and thanks anyway . (The chronometer is in the first lines)