Categories
Mastering Development

Cannot find symbol when I’ve defined it already

I’m making a Guess the Number game, and this is my code for the game.

import java.util.Random;
import java.util.Scanner;

public class Guess {

    public static void main(String[] args) {
        int guess, diff;
        Random random = new Random();
        Scanner in = new Scanner(System.in);
        int number = random.nextInt(100) + 1;
    
        System.out.println("I'm thinking of a number between 1 and 100");
        System.out.println("(including both). Can you guess what it is?");
    
        System.out.print("Type a number: ");
        guess = in.nextInt();
        System.out.printf("Your guess is: %s", guess);
    
        diff = number - guess;
        printf("The number I was thinking of is: %d", guess);
        printf("You were off by: %d", diff);
    }
}

However, when I try to compile it, it comes up with the following error:

Guess.java:20: error: cannot find symbol
        printf("The number I was thinking of is: %d", guess);
        ^
    symbol:   method printf(String,int)
    location: class Guess
Guess.java:21: error: cannot find symbol
       printf("You were off by: %d", diff);
       ^
   symbol:   method printf(String,int)
   location: class Guess
2 errors

What is wrong with the code?

Leave a Reply

Your email address will not be published. Required fields are marked *