Adivina el número aleatorio

This commit is contained in:
PC de clase committed 2026-10-05 11:48:20 +02:00
1 parent 537b8aefc0
commit 8c5d233def
1 file changed
+25
+25
View File
@@ -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();
}