MnMWizard icon

Guessing assignment

MnMWizard | PRO | 12/23/17 06:10:48 PM UTC | 0 ⭐ | 412 👁️ | Never ⏰ | []
text |

820 B

|

None

|

0 👍

/

0 👎

//Mason Marnell - Guessing game
 import static java.lang.System.in;
 import java.util.Scanner;
 public class SumOfDigits {
 		public static void FindNum(int low, int high){
			Scanner kb = new Scanner(in);
			int guess = (low+high-1) /2;
			System.out.println(guess + " enter too high, too low, or correct");
			String ans = kb.nextLine();
			if(ans.toUpperCase().contains("H")){
				FindNum(low,guess-1);
			}
			if(ans.toUpperCase().contains("L")){
				FindNum(guess+1,high);
			}
			if(ans.toUpperCase().contains("C")){
				System.out.println("Correct");
			}
		}
  	public static void main(String[] args) {
		 Scanner keyb = new Scanner(in);
	        System.out.println("Enter the high number to guess");
	        int low = 1;
	        int high = keyb.nextInt();
	        FindNum(1,high);
 	}
 }

Comments