Advertisement
MnMWizard

Guessing assignment

Dec 23rd, 2017
161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.82 KB | None | 0 0
  1. //Mason Marnell - Guessing game
  2.  
  3. import static java.lang.System.in;
  4.  
  5. import java.util.Scanner;
  6.  
  7. public class SumOfDigits {
  8.  
  9. public static void FindNum(int low, int high){
  10. Scanner kb = new Scanner(in);
  11. int guess = (low+high-1) /2;
  12. System.out.println(guess + " enter too high, too low, or correct");
  13. String ans = kb.nextLine();
  14. if(ans.toUpperCase().contains("H")){
  15. FindNum(low,guess-1);
  16. }
  17. if(ans.toUpperCase().contains("L")){
  18. FindNum(guess+1,high);
  19. }
  20. if(ans.toUpperCase().contains("C")){
  21. System.out.println("Correct");
  22. }
  23. }
  24.  
  25.  
  26. public static void main(String[] args) {
  27. Scanner keyb = new Scanner(in);
  28. System.out.println("Enter the high number to guess");
  29. int low = 1;
  30. int high = keyb.nextInt();
  31. FindNum(1,high);
  32.  
  33. }
  34.  
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement