Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class ParseInt {
- public static int parse(String str) {
- if (str.isEmpty()) {
- return 0;
- }
- int num = 0;
- switch (str.charAt(0)) {
- case '1' :
- num = 1;
- break;
- case '2' :
- num = 2;
- break;
- case '3' :
- num = 3;
- break;
- case '4' :
- num = 4;
- break;
- case '5' :
- num = 5;
- break;
- case '6' :
- num = 6;
- break;
- case '7' :
- num = 7;
- break;
- case '8' :
- num = 8;
- break;
- case '9' :
- num = 9;
- break;
- }
- return num * (int) Math.pow(10, str.length() - 1) + parse(str.substring(1));
- }
- }
Add Comment
Please, Sign In to add comment