package singleTon;
public class execToLong {
// int类型存储长度为32bit.所以范围是“-2^32”到“2^32-1”
// 也就是“-2147483648”到“2147483647”
//long 类型的数要大于2147483647
public static void main(String[] args) {
String str = "21128544321";
long a = 0;
char base = '0';
char[] chars = str.toCharArray();
for (int j = 0; j < chars.length; j++) {
//chars[j]-base= 等于原来的数字*数字所在位数 累加即得到最终a的int类型
a += (chars[j] - base) * getPow(10, chars.length - j - 1);
}
System.out.println(a);
}
//eg: 十位就是10 十位数是1 所以得到十位数 1
public static long getPow(long m, long n) {
long sum = 1;
for (int i = 0; i < n; i++) {
sum = sum * m;
}
return sum;
}
}