
Ayuda recuadro java para adivinar un numero
Publicado por Sergio (2 intervenciones) el 16/11/2016 22:35:27
Buenas tengo una duda con este ejercicio, si uso la consola me funciona bien. Pero usando los recuadros no me va...que estoy haciendo mal.
Se que es de novato,pero es que no consigo dar con ello.
Se que es de novato,pero es que no consigo dar con ello.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import java.io.*;
import javax.swing.JOptionPane;
/**
* @author xxx
*
*/
public class AdivinarNumero {
/**
* @param args
* @throws IOException
* @throws
*/
public static void main(String[] args) throws IOException {
// TODO Auto-generated method stub
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int aleatorio = (int) (Math.random()*100);
int numero = 0, intentos = 0;
while(numero!=aleatorio){
intentos++;
//System.out.println("Introduce uno número");
JOptionPane.showInputDialog("Introduce un número, por favor.");
numero = Integer.parseInt(br.readLine());
if(aleatorio<numero){
//System.out.println("Introduce uno más bajo");
JOptionPane.showInputDialog("Introduce uno más bajo");
}
if(aleatorio>numero){
//System.out.println("Introduce uno más alto");
JOptionPane.showInputDialog("Introduce uno mayor");
}
}
JOptionPane.showMessageDialog(null,"Correcto! Lo has conseguido en "+intentos+" intentos");
}
}
Valora esta pregunta


0