How do I test the user's input to see if its words are within a specified range
<p>I'm trying to write a program that asks the user to enter the maximum and minimum values of words they would like to be in the essay, and then enter the essay. The program checks to see if the number of words the user inputted is within the range they specified. Is there a way I can turn my code into a method? Here's my code:     </p>

<p><strong>Desired output:</strong> </p>

<hr>

<pre><code>Please enter the maximum: 9

Please enter the minimum: 5

enter: hello there

2

YAY!!!!!!!!! YOU'RE WTHIN THE RAAAANGE!!!!!!!!!!!!!!!!!!!!!!!
</code></pre>

<hr>

<p><strong>Here's my code:</strong> </p>

<hr>

<pre><code>public static void main(String[] args) {
    Scanner input = new Scanner(System.in);
    System.out.print("\t\tPlease enter the maximum: ");
    int max = input.nextInt();
    System.out.print("\t\tPlease enter the minimum: ");
    int min = input.nextInt();

    System.out.print("enter: ");
    String word = input.next();
    int countwords = 0;

    for (int i = 0; i &lt; word.length(); i++) {
        if (word.charAt(i) == ' ') {
            countwords++;
        }
    }
    countwords++;
    System.out.println(countwords);
    if(countwords&lt;=max &amp;&amp; countwords &gt;=min){
        System.out.println(
            "YAY!!!!!!!!! YOU'RE WTHIN THE RAAAANGE!!!!!!!!!!!!!!!!!!!!!!!"
        );
    }
}
</code></pre>