接受一个 int 的简单方法,检查它是否落在 min/max 中,并返回该值.. 无法突破方法

Simple method for taking in an int, checking if it falls in a min/max, and returning that value.. not able to break out of method

我是 java 的新手,我正在尝试在 class 中创建一个简单的方法,即 returns 一个用户整数,只要它在特定范围内.它似乎正确地检查了输入,但在那之后,它并没有退出该方法。方法如下:

public int readInt(String prompt, int min, int max) {
    int userInt;
    boolean works = true;
    System.out.println(prompt);
    userInt = inputReader.nextInt();
    inputReader.nextLine();
    
    while(works = true) {
        if (userInt >= min && userInt <= max) {
            works = false;
        } else {
        System.out.println("Please enter value between " + min + " and " + max);
        userInt = inputReader.nextInt();
        inputReader.nextLine();
        }
    }
    return userInt;
}

这是主要方法。 运行 方法,然后尝试将 int 打印出来。永远不会到达 sout 线。

public static void main(String[] args) {
    
    UserIO userIO = new UserIOImpl();
    
    int userInt;
    
    userInt = userIO.readInt("Please enter a number between 1 and 10", 1, 10);
    System.out.println(userInt);
}

非常感谢任何正确方向的帮助。

编辑:我目前使用的是 NetBeans 12.0

将“while(works = true)”改为“while(works)”