12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. import java.util.Scanner;
  2. import java.util.ArrayList;
  3. public class Main
  4. {
  5. public static void Main()
  6. {
  7. }
  8. public static void TooLargeTooSmall()
  9. {
  10. Double random = Math.random() * 100.0;
  11. int number1 = random.intValue();
  12. int guesses = 0;
  13. ArrayList<Integer> alreadyGuessed = new ArrayList<Integer>();
  14. boolean win = false;
  15. random = Math.random() * 100.0;
  16. int number2 = random.intValue();
  17. int min = Math.min(number1, number2);
  18. int max = Math.max(number1, number2);
  19. Double randomAnswer = (Math.random() * ((max - min) + 1)) + min;
  20. int answer = randomAnswer.intValue();
  21. System.out.println("Please choose a number between: " + min + " and " + max + ".");
  22. Scanner scanner = new Scanner(System.in);
  23. while(win == false)
  24. {
  25. int guess = scanner.nextInt();
  26. if(alreadyGuessed.indexOf(guess) == -1)
  27. {
  28. alreadyGuessed.add(guess);
  29. }
  30. if(guess == answer){
  31. System.out.println("You win!");
  32. System.out.println("You guessed: " + alreadyGuessed.size());
  33. win = true;
  34. } else if(guess > answer)
  35. {
  36. System.out.println("Too high, guess again:");
  37. } else{
  38. System.out.println("Too low, guess again:");
  39. }
  40. }
  41. }
  42. }