public class MathUtil extends Object
NumberUtil
属于一类工具,NumberUtil偏向于简单数学计算的封装,MathUtil偏向复杂数学计算Constructor and Description |
---|
MathUtil() |
Modifier and Type | Method and Description |
---|---|
static long |
arrangementCount(int n)
计算排列数,即A(n, n) = n!
|
static long |
arrangementCount(int n,
int m)
计算排列数,即A(n, m) = n!
|
static List<String[]> |
arrangementSelect(String[] datas)
全排列选择(列表全部参与排列)
|
static List<String[]> |
arrangementSelect(String[] datas,
int m)
排列选择(从列表中选择n个排列)
|
static double |
centToYuan(long cent)
金额分转换为元
|
static long |
combinationCount(int n,
int m)
计算组合数,即C(n, m) = n!
|
static List<String[]> |
combinationSelect(String[] datas,
int m)
组合选择(从列表中选择n个组合)
|
static BigInteger |
factorial(BigInteger n)
计算阶乘
n!
|
static BigInteger |
factorial(BigInteger start,
BigInteger end)
计算范围阶乘
factorial(start, end) = start * (start - 1) * ... * (end + 1)
|
static long |
factorial(long n)
计算阶乘
n!
|
static long |
factorial(long start,
long end)
计算范围阶乘
factorial(start, end) = start * (start - 1) * ... * (end + 1)
|
static int |
gcd(int a,
int b)
最大公约数
见:https://stackoverflow.com/questions/4009198/java-get-greatest-common-divisor 来自Guava的IntMath.gcd |
static int |
multiple(int m,
int n)
最小公倍数
|
static int |
processMultiple(int selectNum,
int minNum)
可以用于计算双色球、大乐透注数的方法
比如大乐透35选5可以这样调用processMultiple(7,5); 就是数学中的:C75=7*6/2*1 |
static long |
sqrt(long x)
平方根算法
推荐使用 Math.sqrt(double) |
static long |
yuanToCent(double yuan)
金额元转换为分
|
public static long arrangementCount(int n, int m)
n
- 总数m
- 选择的个数public static long arrangementCount(int n)
n
- 总数public static List<String[]> arrangementSelect(String[] datas, int m)
datas
- 待选列表m
- 选择个数public static List<String[]> arrangementSelect(String[] datas)
datas
- 待选列表public static long combinationCount(int n, int m)
n
- 总数m
- 选择的个数public static List<String[]> combinationSelect(String[] datas, int m)
datas
- 待选列表m
- 选择个数public static long yuanToCent(double yuan)
yuan
- 金额,单位元public static double centToYuan(long cent)
cent
- 金额,单位分public static BigInteger factorial(BigInteger n)
n!= n * (n-1) * ... * 2 * 1
n
- 阶乘起始public static BigInteger factorial(BigInteger start, BigInteger end)
factorial(start, end) = start * (start - 1) * ... * (end + 1)
start
- 阶乘起始(包含)end
- 阶乘结束,必须小于起始(不包括)public static long factorial(long start, long end)
factorial(start, end) = start * (start - 1) * ... * (end + 1)
start
- 阶乘起始(包含)end
- 阶乘结束,必须小于起始(不包括)public static long factorial(long n)
n!= n * (n-1) * ... * 2 * 1
n
- 阶乘起始public static long sqrt(long x)
Math.sqrt(double)
x
- 值public static int processMultiple(int selectNum, int minNum)
selectNum
- 选中小球个数minNum
- 最少要选中多少个小球public static int gcd(int a, int b)
a
- 第一个值b
- 第二个值public static int multiple(int m, int n)
m
- 第一个值n
- 第二个值Copyright © 2025. All rights reserved.