手写代码:将字符串转int类型,要求不能用已有的方法
参考回答:
public static int stringToInt(String str) { int result=0; char[] ch=str.toCharArray(); int len=ch.length; for(int i=0;i<len;i++) { result+=(((int)ch[i]-'0')*Math.pow(10, len-1-i)); } return result; }
扫描二维码,关注牛客网
下载牛客APP,随时随地刷题