So I'm currently stuck on a bit of code, because I want to be able to have 2 command line arguments as 2 positive even numbers.
However if the user were to either input a number odd, less than 0 or more or less than 2 arguments, the code must output that the user has input an invalid number of arguments and terminate the program.
This is my code so far and I'm not sure where I'm going wrong:
import java.util.Scanner;
public class Test {
public static void main(String[] args) {
Scanner keyboard = new Scanner(System.in);
int numOne = Integer.parseInt(args[0]);
int numTwo = Integer.parseInt(args[1]);
if ((numOne == null && numTwo == null)) {
System.out.println("Not enough arguments. System terminating");
} else if (numOne == null || numTwo == null) {
System.out.println("terminating program");
}
}
}
Sorry if the code is messy, I'm new to this site and I'm not sure how to get the code settings. Thanks :)
nullcheck before parsing then Integers. You can't pass anulltoparseInt().