From 22ab6c8217dab72455e74775b34b70fcc9c0a4fb Mon Sep 17 00:00:00 2001 From: Nacho Date: Mon, 14 Sep 2026 11:05:47 -0300 Subject: [PATCH] Create adivina_numero.java --- adivina_numero.java | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 adivina_numero.java diff --git a/adivina_numero.java b/adivina_numero.java new file mode 100644 index 0000000..70f3377 --- /dev/null +++ b/adivina_numero.java @@ -0,0 +1,27 @@ +import java.util.Scanner; +import java.util.Random; + +public class adivina_numero { + public static void main(String[] args) { + Scanner sc = new Scanner(System.in); + Random random = new Random(); + int numeroSecreto = random.nextInt(50) + 1; // 1 al 50 + int intento = 0; + + System.out.println("Intenta adivinar el número del 1 al 50!"); + + while (intento != numeroSecreto) { + System.out.print("Introduce tu número: "); + intento = sc.nextInt(); + + if (intento < numeroSecreto) { + System.out.println("El número secreto es mayor."); + } else if (intento > numeroSecreto) { + System.out.println("El número secreto es menor."); + } + } + + System.out.println("¡Felicidades! Adivinaste el número."); + sc.close(); + } +}