Skip to content

Instantly share code, notes, and snippets.

@kiramishima
Last active November 17, 2021 16:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kiramishima/47ec3253560bf12c3425730ed7a43340 to your computer and use it in GitHub Desktop.
Save kiramishima/47ec3253560bf12c3425730ed7a43340 to your computer and use it in GitHub Desktop.
Guess Number
/*
* 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