Skip to content

Instantly share code, notes, and snippets.

@eduardoferron
Created March 24, 2018 21:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eduardoferron/01f303d19fee64250de7cda17b98cfc7 to your computer and use it in GitHub Desktop.
Save eduardoferron/01f303d19fee64250de7cda17b98cfc7 to your computer and use it in GitHub Desktop.
import java.lang.Math; // headers MUST be above the first class
// one class needs to have a main() method
public class HelloWorld
{
// arguments are passed using the text field below this editor
public static void main(String[] args)
{
Integer number = TryParseInt("85");
System.out.print(number + " is a good value\n");
number = TryParseInt("This is not a number");
if (number == null)
System.out.print("Nice try! Wrong number :)");
}
public static Integer TryParseInt(String value)
{
try
{
return Integer.parseInt(value);
}
catch (NumberFormatException ex)
{
return null;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment