mathutil.java
来自「这是一个十分有用的java图形工具包」· Java 代码 · 共 66 行
JAVA
66 行
package net.turbochen.graph.util;
import java.text.NumberFormat;
/**
* 提供数学统计工具.
* @author Turbo Chen
*/
public class MathUtil
{
public static double max(double[] d) throws InvalidDataException
{
if ( d == null ) throw new InvalidDataException();
double temp = d[0];
for ( int i = 0;i<d.length;i++ )
{
if (d[i] > temp ) temp = d[i];
}
return temp;
}
public static double min(double[] d) throws InvalidDataException
{
if ( d == null ) throw new InvalidDataException();
double temp = d[0];
for ( int i = 0;i<d.length;i++ )
{
if (d[i] < temp ) temp = d[i];
}
return temp;
}
public static int max(int[] d) throws InvalidDataException
{
if ( d == null ) throw new InvalidDataException();
if ( d == null ) throw new InvalidDataException();
int temp = d[0];
for ( int i = 0;i<d.length;i++ )
{
if (d[i] > temp ) temp = d[i];
}
return temp;
}
public static int min(int[] d) throws InvalidDataException
{
if ( d == null ) throw new InvalidDataException();
if ( d == null ) throw new InvalidDataException();
if ( d == null ) throw new InvalidDataException();
int temp = d[0];
for ( int i = 0;i<d.length;i++ )
{
if (d[i] < temp ) temp = d[i];
}
return temp;
}
public static String format(double value,String pattern)
{
java.text.DecimalFormat df = new java.text.DecimalFormat(pattern);
return df.format(value);
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?