方法一:double
转 int
import java.io.*;
import java.util.*;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
PrintWriter pw = new PrintWriter(System.out);
double num = Double.parseDouble(br.readLine());
pw.println((int) (num + 0.5));
pw.flush();
pw.close();
br.close();
}
}
方法二:字符串判断
import java.io.*;
import java.util.*;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
PrintWriter pw = new PrintWriter(System.out);
String str = br.readLine();
int index = str.indexOf('.');
String substr = str.substring(0, index);
if (str.charAt(index + 1) < '5') {
pw.println(substr);
} else {
pw.println(Integer.parseInt(substr) + 1);
}
pw.flush();
pw.close();
br.close();
}
}