算法题:取近似值

    xiaoxiao2025-04-17  11

    1.

    public static void main(String[] args) { Scanner sc = new Scanner(System.in); while(sc.hasNextDouble()){ double l=sc.nextDouble(); System.out.println(Math.round(l)); } } Math.round()四舍五入

    2.

    private static void mthod2(){ Scanner scan = new Scanner(System.in); while(scan.hasNext()){ double d = scan.nextDouble(); int dint = (int)d; if((d-dint)>=0.5 && (d-dint)<1) dint++; System.out.println(dint); } }

    转载请注明原文地址: https://ju.6miu.com/read-1298167.html
    最新回复(0)