题解 | #取近似值#
取近似值
https://www.nowcoder.com/practice/3ab09737afb645cc82c35d56a5ce802a
import java.util.Scanner;
// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
public static void main(String[] args) {
String s ="";
Scanner in = new Scanner(System.in);
// 注意 hasNext 和 hasNextLine 的区别
while (in.hasNext()) { // 注意 while 处理多个 case
s = in.next();
}
result(s);
}
private static void result(String s){
String[] s1 = s.split("\\.");
int result = 0;
if(s1.length == 2){
int a0 = Integer.valueOf(s1[0]);
int a1 = Integer.valueOf(s1[1].charAt(0)) -48;
if(a1 >= 5){
result = a0 + 1;
} else{
result = a0;
}
} else {
result = Integer.valueOf(s);
}
System.out.print(result);
}
}
雪域灰灰刷题笔记 文章被收录于专栏
雪域灰灰刷题笔记
