欢迎进入Java社区论坛,与200万技术人员互动交流 >>进入
//先判断原来的值是否大于比较的临界值
if(result>maxLimit){
throw new RuntimeException(”整数越界了”);
}
// 判断当前位的值+ch的值是否》整数的最大值
if(result*10>limit-(ch-‘0’)){
System.out.println(”result–>”+(result*10));
System.out.println(”max—–>”+(Integer.MAX_VALUE));
System.out.println(”result–>”+(Integer.MAX_VALUE-(ch-‘0’))+” ch=”+(ch-‘0’));
throw new RuntimeException(”数组越界了s “);
}
index++;
result=result*10+(ch-‘0’);
}else{
throw new RuntimeException(”不是整数 “);
}
}
//三目运算符
return isPositive?result:-result;
}
}
[1][2]
生命不息,在任何一种博大的辉煌之后,都掩藏着许多鲜为人知的艰难的奋斗。