I am trying to take an input from the user and validate it to make sure it is not a null value. I will also have to convert a string to an integer. I have been trying to use scanner to get this result but with limited success. What am I doing wrong? FYI I am brand new to Java (~two weeks). So please forgive any ignorance that my question may contain.
import java.util.Scanner;
public class NumbersTest {
public static void main(String[] args) {
Scanner userInput = new Scanner(System.in);
String Num = args[0];
int i = Integer.parseInt(Num);
if (userInput == null){
printError();
return;
}
else if (i % 2 == 0){
System.out.println("even");
}
else if (i % 2 != 0){
System.out.println("odd");
}
}
private static void printError() {
System.out.println("Please enter a number.");
}
}