//只能用于单个字符,不可用于23,45,123等进行拼接
public class ToInt {
private static int toInt(int[] arr, int pos, int len) {
int t = 1;
int ans = 0;
for (int i = pos + len - 1; i >= pos; i--) {
ans += arr[i] * t;
t *= 10;
}
return ans;
}
public static void main(String[] args) {
int[] arr = {1, 2, 3, 4, 6, 2, 5};
int i = toInt(arr, 0, 6);
System.out.println(i);
}
}
算法-字符串转整数
最新推荐文章于 2022-01-12 10:18:48 发布