pattern matching will help you to tell if it is a number, but still won't cast it so you'll still need the parse if you want to treat it as a number.
Just try/catch it instead, its much simpler. Integer.parseint will throw a NumberFormatException if it can't be parsed:
PHP Code:
try
{
Integer x = Integer.valueOf(S1);
System.out.println("The int is: " + x);
}
catch (NumberFormatException ex)
{
System.out.println(S1 + " is not a number.");
}