My code worked when it was in the main method, but once I try to put it in its own method, I get "args cannot be resolved to a variable" Also, I am very new to java, is there a way to simplify this code block, I have a book that shows modularized code, but it is not explained in detail.
private static boolean validateInput() {
//if invalid character is entered ie. a letter, will go to the catch
try
{
number1 = Integer.parseInt(args[0]);
}
catch (Exception e)
{
System.out.println("Input #1 is not a valid integer.");
return false;
}
try
{
number2 = Integer.parseInt(args[1]);
}
catch (Exception e)
{
System.out.println("Input #2 is not a valid integer.");
return false;
}
try
{
number3 = Integer.parseInt(args[2]);
}
catch (Exception e)
{
System.out.println("Input #3 is not a valid integer.");
return false;
}
return true;
}