Answer:
public class Question2 {
public static void main(String[] arguments) {
if (arguments.length == 2) {
int firstInteger = Integer.parseInt(arguments[0]);
int secondInteger = Integer.parseInt(arguments[1]);
System.out.println(firstInteger + " + " + secondInteger + " = " + (firstInteger + secondInteger));
System.out.println(firstInteger + " * " + secondInteger + " = " + (firstInteger * secondInteger));
} else {
throw new IllegalArgumentException();
}
}
}
Step-by-step explanation:
- Inside the main method, check whether the length of arguments is equal to 2, and then store the arguments in the variables called firstInteger and secondInteger respectively.
- The next step is to display the sum and product of both firstInteger and secondInteger inside the if block.
- Otherwise, if the length of arguments is not equal to 2, then throw an IllegalArgumentException.