Created
April 6, 2017 07:04
-
-
Save ababup1192/8283cae04ddbcf9bd19789b7a0201365 to your computer and use it in GitHub Desktop.
fuck code.
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.util.Map; | |
import java.util.HashMap; | |
public class Main { | |
private Map<String, String> map; | |
public Main() { | |
Map<String, String> map = new HashMap<String, String>(); | |
map.put("a", "123"); | |
map.put("b", "d"); | |
map.put("c", "456"); | |
System.out.println(getValueAsInt("a")); | |
System.out.println(getValueAsInt("b")); | |
System.out.println(getValueAsInt("c")); | |
} | |
public int getValueAsInt(String key) { | |
if(map.get(key) == null){ | |
return -1; | |
} else { | |
int res; | |
try{ | |
res = Integer.parseInt(map.get(key)); | |
} catch(NumberFormatException e) { | |
e.printStackTrace(); | |
res = -1; | |
} | |
return res; | |
} | |
} | |
public static void main(String args[]){ | |
new Main(); | |
} | |
} |
hishidama
commented
Apr 6, 2017
•
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment