Pagini recente » Cod sursa (job #591184) | Cod sursa (job #743780) | Cod sursa (job #3289255) | Cod sursa (job #2628022) | Cod sursa (job #3146541)
import java.util.Scanner;
import static java.lang.System.out;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int left = 1;
int right = sc.nextInt();
while (left < right) {
int half = (left + right) / 2;
out.println("? " + half);
switch (sc.nextInt()) {
case 0 -> left = half + 1;
case 1 -> right = half;
default -> {
return;
}
}
}
out.println("! " + left);
out.flush();
}
}