public class TestDemo { public static void main(String args[]) { TestDemo s = new TestDemo(); s.String2Int("1234455"); } public void String2Int(String s) { //先将字符串转为字符型数组String.toCharArray() char[] c = s.toCharArray(); Integer[] ints = new Integer[c.length]; for (int i = 0; i < c.length; i++) { ints[i] = c[i] - '0'; } Double result = 0D; for (int i = 0; i < ints.length; i++) { // Math.pow得到的是一个Double型,所以result也要定义为Double型 result += (ints[i] * Math.pow(10, (ints.length - 1 - i))); } Integer n = result.intValue();// Double型转换成int型直接使用intValue()即可 System.out.println(n); } }