-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathWhileLoops.java
More file actions
29 lines (19 loc) · 1.09 KB
/
WhileLoops.java
File metadata and controls
29 lines (19 loc) · 1.09 KB
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
public class WhileLoops {
public static void main(String[] args) {
//Ejercicio 1: Escribe un bucle while que genere números aleatorios hasta que salga el número 7. Has de usar la función getRandomNumber
//Ejercicio 2: Escribe un bucle while que genere números aleatorios hasta que salga un número mayor a 70. Has de usar la función getRandomNumber
//Ejercicio 3: Escribe un bucle do while que genere un número aleatorio entre 1 y 100. El usuario debe adivinar el número aleatorio y el programa debe seguir solicitando intentos hasta que el usuario adivine correctamente. Después de cada intento, el programa debe indicar si el número ingresado es mayor o menor que el número generado. Has de usar la función getRandomNumber
}
/**
* Function name: getRandomNumber
*
* @param number (int)
* @return (int)
*
* Inside the function:
* 1. choose a random integer between 1 and the number given
*/
public static int getRandomNumber(int number){
return (int)(Math.random() * number) + 1;
}
}