寫出一個程序,接受一個浮點數值,輸出該數值的近似整數值。若是小數點後數值大於等於5,向上取整;小於5,則向下取整。
輸入一個浮點數值
輸出該數值的近似整數值
輸出該數值的近似整數值
6
import java.util.Scanner; /** * * All Rights Reserved !!! */ public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); while (scanner.hasNext()) { float input = scanner.nextFloat(); System.out.println(floatToNearInt(input)); } scanner.close(); } private static int floatToNearInt(float f) { return (int) ((f*10 + 5)/10); } }