Created
March 24, 2018 21:17
-
-
Save eduardoferron/01f303d19fee64250de7cda17b98cfc7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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