APL/APL2.1/TP15/Devinette/Devinette.java

55 lines
1.6 KiB
Java
Raw Normal View History

2022-05-24 17:28:29 +02:00
package Devinette;
import java.io.BufferedInputStream;
import java.io.BufferedReader;
import java.io.DataInputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
public class Devinette {
public static void main(String[] args) {
int rand = 0;
try (DataInputStream ois = new DataInputStream(new FileInputStream("/dev/random"))){
try {
rand = ois.readInt() % 100 + 1;
System.out.println(rand);
} catch (IOException e) {
System.err.println(e);
System.exit(1);
}
try {
ois.close();
} catch (IOException e) {
System.err.println(e);
System.exit(1);
}
} catch (IOException e) {
System.err.println(e);
System.exit(1);
}
try (BufferedReader ois = new BufferedReader(new InputStreamReader(System.in))) {
for (int i = 0; i < 5; i++) {
int guess = Integer.parseInt(ois.readLine());
System.out.println(guess + " " + rand);
if (guess == rand) {
System.out.println("Gagné !");
return;
} else if (guess > rand) {
System.out.println("-");
} else if (guess < rand) {
System.out.println("+");
}
}
System.out.println("Perdu !");
} catch (IOException e) {
System.exit(1);
}
}
}