题解 | #取近似值#
取近似值
https://www.nowcoder.com/practice/3ab09737afb645cc82c35d56a5ce802a
import java.util.Scanner; //TIP 要<b>运行</b>代码,请按 <shortcut actionId="Run"/> 或 // 点击装订区域中的 <icon src="AllIcons.Actions.Execute"/> 图标。 public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); while (sc.hasNext()) { String a = sc.nextLine(); String b; if (!a.contains(".")) { b = "0"; } else { b = a.split("\\.")[1]; } if (Integer.parseInt(b.substring(0, 1)) >= 5) { System.out.println(Integer.parseInt(a.split("\\.")[0]) + 1); } else { System.out.println(Integer.parseInt(a.split("\\.")[0])); } } } }
分割字符串即可