Main.java 1.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. /**
  2. * Created by iyasuwatts on 10/17/17.
  3. */
  4. import java.util.Scanner;
  5. import java.util.Random;
  6. public class Main {
  7. public static void main(String[] args){
  8. Scanner input = new Scanner(System.in);
  9. int randNumb;
  10. int guess;
  11. int numbAtempts=0;
  12. Random genRand = new Random();
  13. randNumb= genRand.nextInt(100) +1;
  14. int lastInput;
  15. System.out.println ("I'm thinking off a number between 1 to 100?:");
  16. guess=input.nextInt();
  17. lastInput=guess;
  18. while (guess !=randNumb ){
  19. if (guess> randNumb){
  20. System.out.println("Your number is too BIG ");
  21. guess=input.nextInt();
  22. numbAtempts+=1;
  23. } else {
  24. System.out.println("Your number is too SMALL");
  25. guess=input.nextInt();
  26. numbAtempts+=1;
  27. }
  28. }
  29. System.out.println(randNumb + " is the right number and it only took you" +" "+ (numbAtempts + 1) + " tries");
  30. }
  31. }