diff --git a/src/Random.java b/src/Random.java new file mode 100644 index 0000000..94b41e4 --- /dev/null +++ b/src/Random.java @@ -0,0 +1,25 @@ +// Diseña un alrogitmo que cree un número aleatorio y te permita +// itroducir otros números hasta que lo adivines. + +void main() { + Scanner sc = new Scanner(System.in); + Random r = new Random(); + int secreto = r.nextInt(100) + 1; // 1-100 + boolean interruptor = true; + + int n; + do { + System.out.println("Adivina el número (1-100)"); + n = sc.nextInt(); + if (n > secreto) { + System.out.println("Te has pasado"); + } else if (n < secreto) { + System.out.println("Te has quedado corto"); + } else { + System.out.println("Has acertado!!!"); + interruptor = false; + } + } while (interruptor); + + sc.close(); + } \ No newline at end of file