算法题:取近似值

论坛 期权论坛 编程之家     
选择匿名的用户   2021-6-2 17:46   1561   0



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);
         }
 }



分享到 :
0 人收藏
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

积分:3875789
帖子:775174
精华:0
期权论坛 期权论坛
发布
内容

下载期权论坛手机APP