Interactive Problems in Competitive Programming |  ; Applying Binary Search interactively ; Print the guessed number ; Input the response from the judge
import java . util . * ; class GFG { public static void main ( String [ ] args ) { Scanner sc1 = new Scanner ( System . in ) ; int lower_bound = 2 ; int upper_bound = 10 ; while ( lower_bound <= upper_bound ) { int mid = ( lower_bound + upper_bound ) / 2 ; System . out . println ( mid ) ; int response = sc1 . nextInt ( ) ; if ( response == - 1 ) { lower_bound = mid + 1 ; } else if ( response == 1 ) { upper_bound = mid - 1 ; } else if ( response == 0 ) { System . out . println ( " Number ▁ guessed ▁ is ▁ : " + mid ) ; break ; } } } }