年轻人不讲码德
取近似值
http://www.nowcoder.com/questionTerminal/3ab09737afb645cc82c35d56a5ce802a
import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); while(sc.hasNext()) { String inputStr = sc.nextLine(); int pi = inputStr.indexOf("."); String r = inputStr.substring(0, pi); int ri = Integer.parseInt(r); String f = inputStr.substring(pi+1); int fi = Integer.parseInt(f); if( fi>=0 && fi<5 ) { System.out.println(ri); } else { System.out.println(ri+1); } } } }
采用字符串截取并转化,菜鸟一枚~