Exercise for playing wordgames with user input I'm trying to getting integer keyboard input to call the corresponding method.
invalid input works, keyboard input 3 works, input 2 exits, input 1 calls the wrong method.
I've not yet worked on the subtring and points problem method yet.
Regards, and I appreciate your feedback.
import java.io.File;
import java.util.Scanner;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.util.InputMismatchException;



public class WordGames {

public static void main(String[] args) throws FileNotFoundException {


    getSelection();
    File file = new File(&quot;DICTIONARY.txt&quot;);
        if (file.isFile() == true) {
        }
        else {
            System.out.println(&quot;File doesn't exist.  Exiting.&quot;);
            System.exit(0);  
        }
    
    subStringProblem();
    pointsProblem();
            
    }
    
    static String getSelection() {
        Scanner keyboardInput = new Scanner(System.in);
        System.out.println(&quot;Welcome to the Word Games program menu.&quot;);
        System.out.println(&quot;Select from one of the following options.&quot;);
        System.out.println(&quot;1. Substring problem.&quot;);
        System.out.println(&quot;2. Points problem.&quot;);
        System.out.println(&quot;3. Exit.&quot;);
        System.out.println(&quot;Enter your selections: &quot;);
        
        
        if ( ! keyboardInput.hasNextInt()) {
           
           System.out.println(&quot;Invalid option.  Try again.&quot;);
           getSelection();
            
        } else if (keyboardInput.hasNextInt(1)){
            subStringProblem(); 
            getSelection();
            
        } else if (keyboardInput.hasNextInt(2)){
            pointsProblem();
            getSelection();
            
        } else if (keyboardInput.hasNextInt(3)){
        }    System.out.println(&quot;Good Bye!&quot;);
             System.exit(0);  
        return null;
    }
        
        
    static String subStringProblem() {
        System.out.println(&quot;Substring problem.&quot;);
        System.out.println(&quot;Enter a Substring:&quot;);
    return null;
    }
    static String pointsProblem() {
        System.out.println(&quot;Points problem.&quot;);
        
    return null;
    }
}
1. Proper indentation
Please have a look at a style guide. One important topic of style guides is how to &quot;correctly&quot; indent your code:
import java.io.File;
import java.util.Scanner;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.util.InputMismatchException;

public class WordGames {

    public static void main(String[] args) throws FileNotFoundException {
        getSelection();
        File file = new File(&quot;DICTIONARY.txt&quot;);
        if (file.isFile() == true) {
        }
        else {
            System.out.println(&quot;File doesn't exist.  Exiting.&quot;);
            System.exit(0);  
        }

        subStringProblem();
        pointsProblem();
    }
    
    static String getSelection() {
        Scanner keyboardInput = new Scanner(System.in);
        System.out.println(&quot;Welcome to the Word Games program menu.&quot;);
        System.out.println(&quot;Select from one of the following options.&quot;);
        System.out.println(&quot;1. Substring problem.&quot;);
        System.out.println(&quot;2. Points problem.&quot;);
        System.out.println(&quot;3. Exit.&quot;);
        System.out.println(&quot;Enter your selections: &quot;);
              
        if (!keyboardInput.hasNextInt()) {
           
           System.out.println(&quot;Invalid option.  Try again.&quot;);
           getSelection();
            
        } else if (keyboardInput.hasNextInt(1)) {
            subStringProblem(); 
            getSelection();
            
        } else if (keyboardInput.hasNextInt(2)) {
            pointsProblem();
            getSelection();
            
        } else if (keyboardInput.hasNextInt(3)) {
            System.out.println(&quot;Good Bye!&quot;);
            System.exit(0);
        }  
        return null;
    }
            
    static String subStringProblem() {
        System.out.println(&quot;Substring problem.&quot;);
        System.out.println(&quot;Enter a Substring:&quot;);
        return null;
    }
    
    static String pointsProblem() {
        System.out.println(&quot;Points problem.&quot;);     
        return null;
    }
}

2. Empty if
if (file.isFile() == true) {
}
else {
    System.out.println(&quot;File doesn't exist.  Exiting.&quot;);
    System.exit(0);  
}

This is not necessary. Just use
if (file.isFile()) {
}
else {
    System.out.println(&quot;File doesn't exist.  Exiting.&quot;);
    System.exit(0);  
}

Without an == the if will automatically check if the value is true.
Even better:
if(!file.isFile()) {
    System.out.println(&quot;File doesn't exist.  Exiting.&quot;);
    System.exit(0);  
}

Empty if-statements should be avoided.
3.Input validation
In getSelection(), your program doesn't crash when the user enters a letter instead of a number. That is good. But your program does crash, when the user enters a number not equal to 1, 2 or 3. This problem can be avoided like this:
int sel = 0;
try{
    sel = keyboardInput.nextInt();
} catch (InputMismatchException e){
    keyboardInput.next();
    System.out.println(&quot;Invalid option. Try again.&quot;);
    getSelection();
}

if (sel == 1) {
    subStringProblem(); 
    getSelection();
}
else if (sel == 2) {
    pointsProblem();
    getSelection();
}   
else if (sel == 3) {
    System.out.println(&quot;Good Bye!&quot;);
    System.exit(0);
}
else {
    System.out.println(&quot;Invalid option. Try again.&quot;);
    getSelection();
}

If you are not familiar with try-catch yet, I suggest reading the documentation.
4.Unnecessary returns
If you don't want to return something in your methods, you can use void as return type instead of String.
For example:
static String subStringProblem() {
    System.out.println(&quot;Substring problem.&quot;);
    System.out.println(&quot;Enter a Substring:&quot;);
    return null;
}

should be replaced with
static void subStringProblem() {
    System.out.println(&quot;Substring problem.&quot;);
    System.out.println(&quot;Enter a Substring:&quot;);
}

5. Access modifiers
It is considered good practice to always add Access modifiers to your methods. Instead of
static void getSelection() {

it should be
private static void getSelection() {

6. throws
The throws-keyword in the main-method is not necessary.
Code
import java.io.File;
import java.util.Scanner;
import java.io.FileInputStream;
import java.util.InputMismatchException;

public class WordGames {

    public static void main(String[] args) {
        getSelection();
        File file = new File(&quot;DICTIONARY.txt&quot;);
        if(!file.isFile()) {
            System.out.println(&quot;File doesn't exist. Exiting.&quot;);
            System.exit(0);  
        }
        subStringProblem();
        pointsProblem();
    }
    
    private static void getSelection() {
        Scanner keyboardInput = new Scanner(System.in);
        System.out.println(&quot;Welcome to the Word Games program menu.&quot;);
        System.out.println(&quot;Select from one of the following options.&quot;);
        System.out.println(&quot;1. Substring problem.&quot;);
        System.out.println(&quot;2. Points problem.&quot;);
        System.out.println(&quot;3. Exit.&quot;);
        System.out.println(&quot;Enter your selections: &quot;);
         
        int sel = 0;
        try{
            sel = keyboardInput.nextInt();
        } catch (InputMismatchException e){
            keyboardInput.next();
            System.out.println(&quot;Invalid option. Try again.&quot;);
            getSelection();
        }
        
        if (sel == 1) {
            subStringProblem(); 
            getSelection();
        }
        else if (sel == 2) {
            pointsProblem();
            getSelection();
        }   
        else if (sel == 3) {
            System.out.println(&quot;Good Bye!&quot;);
            System.exit(0);
        }
        else {
            System.out.println(&quot;Invalid option. Try again.&quot;);
            getSelection();
        }
    }
            
    private static void subStringProblem() {
        System.out.println(&quot;Substring problem.&quot;);
        System.out.println(&quot;Enter a Substring:&quot;);
    }

    private static void pointsProblem() {
        System.out.println(&quot;Points problem.&quot;);     
    }
}