常见对象_Math类概述和方法使用
来源:互联网 发布:软件开发工作 编辑:程序博客网 时间:2024/04/28 19:42
package cn.itcast_01;/* * Math:用于数学运算的类。 * 成员变量: * public static final double PI:π圆周率 *public static final double E:自然对数 * 成员方法: * public static int abs(int a):绝对值 * public static double ceil(double a):向上取整 * public static double floor(double a):向下取整 * public static int max(int a,int b):最大值 * public static int min(int a,int b):最小值 * public static double pow(double a,double b):a的b次幂 * public static double random():随机数[0.0,0.1](包左不包右) * public static int round(float a):四舍五入(int接收a+0.5) * public static long round(double a):四舍五入(long接收a+0.5) * public static double sqrt(double a):正平方根 */public class MathDemo {public static void main(String[] args) {// public static final double PISystem.out.println("PI:" + Math.PI);// public static final double ESystem.out.println("E:" + Math.E);System.out.println("----------------");// public static int abs(int a):绝对值System.out.println("abs:" + Math.abs(10));System.out.println("abs:" + Math.abs(-10));System.out.println("----------------");// public static double ceil(double a):向上取整System.out.println("ceil:" + Math.ceil(12.34));System.out.println("ceil:" + Math.ceil(12.56));System.out.println("----------------");// public static double floor(double a):向下取整System.out.println("floor:" + Math.floor(12.34));System.out.println("floor:" + Math.floor(12.56));System.out.println("----------------");// public static int max(int a,int b):最大值System.out.println("max:" + Math.max(12, 23));// 需求:我要获取三个数据中的最大值// 方法的嵌套调用System.out.println("max:" + Math.max(Math.max(12, 23), 18));// 需求:我要获取四个数据中的最大值System.out.println("max:"+ Math.max(Math.max(25, 12), Math.max(15, 45)));// public static int min(int a,int b):最小值System.out.println("min:" + Math.min(12, 23));// 需求:我要获取三个数据中的最小值// 方法的嵌套调用System.out.println("min:" + Math.min(Math.min(12, 23), 18));// 需求:我要获取四个数据中的最小值System.out.println("min:"+ Math.min(Math.min(25, 12), Math.min(15, 45)));System.out.println("----------------");// public static double pow(double a,double b):a的b次幂System.out.println("pow:" + Math.pow(2, 3));System.out.println("----------------");// public static double random():随机数[0.0,0.1](包左不包右)System.out.println("random:" + Math.random());// 获取一个1-100之间的随机数System.out.println("random:" + (int) ((Math.random() * 100) + 1));System.out.println("----------------");// public static int round(float a):四舍五入(int接收)System.out.println("round:" + Math.round(12.34f));System.out.println("round:" + Math.round(12.56f));System.out.println("----------------");// public static long round(double a):四舍五入(long接收)System.out.println("round:" + Math.round(12.34));System.out.println("round:" + Math.round(12.56));System.out.println("----------------");// public static double sqrt(double a):正平方根System.out.println("sqrt:"+Math.sqrt(4));}}
0 0
- 常见对象_Math类概述和方法使用
- 常见对象_Random类的概述和方法使用
- 常见对象_Arrays工具类的概述和使用
- 常见对象_Scanner的概述和构造方法原理
- 常见对象_BigInteger的概述和构造方法
- 常见对象_Date的概述和构造方法
- 黑马程序员_Math类各种方法详解
- 常见对象_正则表达式的概述和基本使用
- 常见对象_Calendar类的概述和获取日历字段的方法
- 244_Math.Random使用
- 常见对象_Pattern和Matcher的概述
- 常见对象_BigDecimal的引入和概述
- 【JavaSE笔记】Java常用类及其方法(十)_Math
- String类的概述及常见方法使用
- 常见对象_Eclipse的概述使用、API的概述、Object类总结
- 常见对象_Object类的概述、hashCode()方法、getClass()方法、toString()方法
- 黑马程序员_Math类
- 常见对象_String类的概述
- Android Material Design之Snackbar
- Codeforces Round #381 (Div. 2) C Alyona and mex (构造)
- maven搭建
- 第五十五天学习笔记
- 自己写的驱动用CreateFile打开时错误码返回1的问题
- 常见对象_Math类概述和方法使用
- poj 3522 Slim Span(最小生成树 Kruskal算法)
- 【unity实用技能】线性差值计算实现
- __attribute__函数的作用
- MFC中MessageBox的用法
- 【工作记录】软件开机自启、关闭自启操作
- 机器学习第九课,经验风险最小化
- Linux下同步工具inotify+rsync使用详解
- CentOS上安装配置MySQL