zoukankan      html  css  js  c++  java
  • Math类

     1 package Format_daqo;
     2 
     3 import java.util.Scanner;
     4 
     5 public class Maths {
     6 
     7     public static void main(String[] args) {
     8         Scanner sc=new Scanner(System.in);
     9         
    10         System.out.println("请输入一个小数:");
    11         double num=sc.nextDouble();
    12         //显示大于num的最小整数,在控制台打印输出
    13         System.out.println("ceil  "+Math.ceil(num));
    14          
    15         //显示最近的最大整数
    16         System.out.println("floor  "+Math.floor(num));
    17         
    18         //求绝对值
    19         System.out.println("abs绝对值     "+Math.abs(num));
    20         
    21         //取浮点数的两种方法         四舍五入
    22         System.out.println("四舍五入"+Math.round(num));
    23         System.out.println();
    24         
    25         //取最大值  最小值
    26         System.out.println(Math.max(10, 200));
    27         System.out.println(Math.min(10, 200));
    28         
    29         //平方根
    30         System.out.println("平方根"+Math.sqrt(100));
    31         
    32         //n次方
    33         System.out.println("n次方      "+Math.pow(2,2));//2的6次方
    34         
    35         //立方根
    36         System.out.println("27立方根      "+Math.cbrt(27));
    37         
    38         //取整,截取小数部分
    39         System.out.println("取整,截取小数部分    "+Math.rint(12.123));
    40     }
    41 }
     1 请输入一个小数:
     2 12.1513
     3 ceil  13.0
     4 floor  12.0
     5 abs绝对值     12.1513
     6 四舍五入12
     7 
     8 200
     9 10
    10 平方根10.0
    11 n次方      4.0
    12 27立方根      3.0
    13 取整,截取小数部分    12.0
  • 相关阅读:
    nio的学习
    并发编程学习(二)
    并发编程学习(一)
    linux基础知识-常用命令
    linux基础知识-目录结构
    springcloud的config
    zuul学习
    hystrix学习
    feign学习
    ribbon学习
  • 原文地址:https://www.cnblogs.com/1020182600HENG/p/5895890.html
Copyright © 2011-2022 走看看