Last active
November 17, 2021 16:28
-
-
Save kiramishima/47ec3253560bf12c3425730ed7a43340 to your computer and use it in GitHub Desktop.
Guess Number
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Author: Paul Arizpe | |
*/ | |
import java.util.Scanner; | |
public class App { | |
public static void main(String[] args) throws Exception { | |
int x = (int)(100 * Math.random()); | |
boolean isFound = false; | |
int tries = 0; | |
Scanner input = new Scanner(System.in); | |
System.out.println("Estoy pensando en un número entre el 1 al 100\n¿En que número estoy pensando?"); | |
while (!isFound) { | |
int tmp = input.nextInt(); | |
if (tmp == x) { | |
isFound = true; | |
System.out.println("Wow !! Felicidades has adivinado"); | |
System.out.printf("Números de intentos: %d", tries); | |
} else { | |
tries++; | |
if (tmp > x) { | |
System.out.println("El número que proporcionaste es demasiado grande"); | |
} else { | |
System.out.println("El número que proporcionaste es muy pequeño"); | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment