添加corejava第11版源码
日期:2019-5-22
This commit is contained in:
1 parent
e199db7c36
commit
af9d779c86
525 files changed
+91425
No files matched your search
@@ -0,0 +1,78 @@
|
||||
package staticInnerClass;
|
||||
|
||||
/**
|
||||
* This program demonstrates the use of static inner classes.
|
||||
* @version 1.02 2015-05-12
|
||||
* @author Cay Horstmann
|
||||
*/
|
||||
public class StaticInnerClassTest
|
||||
{
|
||||
public static void main(String[] args)
|
||||
{
|
||||
var values = new double[20];
|
||||
for (int i = 0; i < values.length; i++)
|
||||
values[i] = 100 * Math.random();
|
||||
ArrayAlg.Pair p = ArrayAlg.minmax(values);
|
||||
System.out.println("min = " + p.getFirst());
|
||||
System.out.println("max = " + p.getSecond());
|
||||
}
|
||||
}
|
||||
|
||||
class ArrayAlg
|
||||
{
|
||||
/**
|
||||
* A pair of floating-point numbers
|
||||
*/
|
||||
public static class Pair
|
||||
{
|
||||
private double first;
|
||||
private double second;
|
||||
|
||||
/**
|
||||
* Constructs a pair from two floating-point numbers
|
||||
* @param f the first number
|
||||
* @param s the second number
|
||||
*/
|
||||
public Pair(double f, double s)
|
||||
{
|
||||
first = f;
|
||||
second = s;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the first number of the pair
|
||||
* @return the first number
|
||||
*/
|
||||
public double getFirst()
|
||||
{
|
||||
return first;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the second number of the pair
|
||||
* @return the second number
|
||||
*/
|
||||
public double getSecond()
|
||||
{
|
||||
return second;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Computes both the minimum and the maximum of an array
|
||||
* @param values an array of floating-point numbers
|
||||
* @return a pair whose first element is the minimum and whose second element
|
||||
* is the maximum
|
||||
*/
|
||||
public static Pair minmax(double[] values)
|
||||
{
|
||||
double min = Double.POSITIVE_INFINITY;
|
||||
double max = Double.NEGATIVE_INFINITY;
|
||||
for (double v : values)
|
||||
{
|
||||
if (min > v) min = v;
|
||||
if (max < v) max = v;
|
||||
}
|
||||
return new Pair(min, max);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user