scanf(%d, &guess);
In Java, you would use the `Scanner` class to read user input, not `scanf`. Here's how you can do it: ```java import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); System.out.print("Enter your guess: "); int guess = scanner.nextInt(); scanner.close(); // Now you can use the guess variable } } ``` However, if you're looking for a direct equivalent of `scanf` in Java, you can use the `BufferedReader` class along with `readInt()` method from `java.util.InputMismatchException` to handle the exception: ```java import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.InputMismatchException; public class Main { public static void main(String[] args) { BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); try { System.out.print("Enter your guess: "); int guess = Integer.parseInt(reader.readLine()); // Now you can use the guess variable } catch (IOException e) { System.out.println("Error reading input."); } catch (NumberFormatException e) { System.out.println("Invalid input. Please enter a number."); } } } ``` But keep in mind that `BufferedReader` is generally slower than `Scanner` for reading simple input like integers.