class HW1 {
public static void main(String[] args) {
double[] test = new double[]{5.2, 1.0, 6.7, 3.4, 100.5, 55.5};
BoundryValues boundryValues = getBoundryValues(test);
System.out.println("Min Value = " + boundryValues.getMin());
System.out.println("Max Value = " + boundryValues.getMax());
System.out.println("Ave Value = " + boundryValues.getAve());
}
private static class BoundryValues {
private double max;
private double min;
private double ave;
public BoundryValues(){}
public BoundryValues(double max, double min, double ave) {
this.max = max;
this.min = min;
this.ave = ave;
}
public void setMax(double max) {
this.max = max;
}
public double getMax() {
return max;
}
public void setMin(double min) {
this.min = min;
}
public double getMin() {
return min;
}
public void setAve(double ave) {
this.ave = ave;
}
public double getAve() {
return ave;
}
}
public static BoundryValues getBoundryValues(double[] doubles) {
BoundryValues boundryValues = new BoundryValues();
double[] results = sort(doubles);
double total = 0.0;
for (int i = 0; i < results.length; i ++) {
total += results[i];
}
boundryValues.setMin(results[0]);
boundryValues.setMax(results[results.length - 1]);
boundryValues.setAve(total/results.length);
return boundryValues;
}
public static double[] sort(double[] doubles) {
for (int i = 0; i < doubles.length; i ++) {
for (int j = 0; j < doubles.length - i - 1; j ++) {
if (doubles[j] > doubles[j + 1]) {
double temp = doubles[j];
doubles[j] = doubles[j + 1];
doubles[j + 1] = temp;
}
}
}
return doubles;
}
}
import java.util.*;
class HW2 {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
double a, b, c;
System.out.println("Enter a, b, c:");
a = scanner.nextDouble();
b = scanner.nextDouble();
c = scanner.nextDouble();
Setsets = calculate(a, b, c);
for (Double d : sets) {
System.out.println("Values are: " + d + "\n");
}
}
public static Setcalculate(double a, double b, double c) {
Setsets = new HashSet ();
if (Math.pow(b, 2.0) - 4 * a * c < 0) {
System.err.println("No value");
} else {
sets.add((- b + Math.sqrt(Math.pow(b, 2.0) - 4 * a * c)) / 2.0 * a);
sets.add((- b - Math.sqrt(Math.pow(b, 2.0) - 4 * a * c)) / 2.0 * a);
}
return sets;
}
}
下午接着写