Q:

How can I check with nextLine() if the user input is only a number or also letters?

I´m having a question about my program. I´m trying to figure out, how i can check if the s.nextLine() input form a user is only holding ints form 1 to 49 in it or also letters.
I know that the "eingabe" is a string so I can’t just use an if right?
My problem is, that I´m relative new in programming with java and i have no idea for a solution.  :/
Maybe you can help me that would be great!
    public static int Scanner() {
        Scanner s = new Scanner(System.in);
        String eingabe = s.nextLine();

        //???

        return eingabe;
    }

A:

import java.util.Scanner;
import java.util.regex.Pattern;
import java.util.regex.Matcher;
class MyClass {
    public static void main (String[] args) {
       try {
                int x = Scanner();
                if(x >= 1 && x <= 49) {
                    System.out.println("Yes");
                }
                else {
                    System.out.println("No");
                }
        }
        catch(java.lang.NumberFormatException e) {
            System.out.println(e);
        }
        //Second Method Using Regex.
        try {
            int x = useRegex();
                if(x >= 1 && x <= 49) {
                    System.out.println("Yes");
                }
                else {
                    System.out.println("No");
                }
        } catch(java.lang.NumberFormatException e) {

            System.out.println(e);
        }
    }
    public static int Scanner() {
        Scanner s = new Scanner(System.in);
        String eingabe = s.nextLine();
        return Integer.parseInt(eingabe);
    }

    public static int useRegex() {
        Scanner s2 = new Scanner(System.in);
        String eingabe = s2.nextLine();
        Pattern p = Pattern.compile("^[\\+-]?\\d+$");
        Matcher m = p.matcher(eingabe);
        boolean b = m.matches();
        if(b) {
            return Integer.parseInt(eingabe);
        }

        else {
            throw new java.lang.NumberFormatException();
        }
    }

}  

Here I am using try catch block to handle if the input format is wrong. If it is wrong then the Exception

java.lang.NumberFormatException

will occur and then if it is a valid number then I am checking whether it is between 1 and 49. Integer.parseInt(num) is used to convert a String into number. 
https://docs.oracle.com/javase/7/docs/api/java/lang/Integer.html#parseInt(java.lang.String).
Try catch is used to handle to exceptions without . See here
By using regex also I have mentioned. See this for regex

