
https://ac.nowcoder.com/acm/problem/22006 牛客网上的一道题 四舍五入
while (true){
System.out.print("请输入(输入-1结束):");
Scanner in = new Scanner(System.in);
String next = in.next();
if (next.equals("-1")){
break;
}
Integer[] szNum = new Integer[next.length()];
for (int a = 0; a < next.length(); a++){
szNum[a] = Integer.parseInt(next.substring(a, a + 1));
}
for (int x = szNum.length - 1; x > -1; x--){
if (szNum[x] > 4 && x > 0){
szNum[x - 1] = szNum[x - 1] + 1;
szNum[x] = 0;
}else{
if (x == szNum.length - 1){
szNum[x] = 0;
}
break;
}
}
String num = "";
for (Integer integer : szNum) {
num += integer;
}
System.out.println(Arrays.toString(szNum));
System.out.println("最终数字:" + num);
}
试下这个,可以在int数值的范围内无线向上四舍五入