/** * Author: Josiah Yoder et al. * User: yoder * Class: SE1011-051 * Lesson: Week 9, Day 2 */ import java.util.Arrays; import java.util.Collections; import java.util.List; import java.util.Scanner; //import org.apache.commons.lang.ArrayUtils; public class Example051_9_2 { /* * This is a scratch-paper method */ public static void main(String[] ignored) { Example051_9_2 example = new Example051_9_2(); example.testArrayMax(); // // Can also use with objects. // Complex051_9_2[] complexNumbers = new Complex051_9_2[5]; // // complexNumbers[0] = new Complex051_9_2(3,6); // // // Complex051_9_2 c0 = complexNumbers[0]; // Complex051_9_2 c1 = complexNumbers[1]; // // c0.add(c1); // c0.add(5.0); // // System.out.println("The magnitude of c0 is " + c0.magnitude()); //========================== // // See also: RandomFun051_9_2 // // For the fun but very poor encryption algorithm // //========================== } public static void buggyProgram() { // The start of a program to read in values from a user // and fill them into the array // until the user enters a 0.0. final int MAX_NUMBER_YEARS = 20; double[] topScores = new double[MAX_NUMBER_YEARS]; // aside double topScores2[] = new double[MAX_NUMBER_YEARS]; // input == 10.0 // Math.abs(input - 10.0) > 0.001 // BUGGY PROGRAM int i = 0; Scanner in = new Scanner(System.in); double input; do { System.out.println("Enter the score for year "+(i+1)+": "); input = in.nextDouble(); topScores[i] = input; i++; }while(Math.abs(input) > 0.0001 && i < 20); for(i=0; i< topScores.length; i++) { System.out.println("The "+(i+1)+"th annual score was "+topScores[i]); } } public void testArrayMax() { char[] a = {'3', '5', '1', '4', '2'}; List b = Arrays.asList(a); // Produces run-time exception. char result = ((Character)(Collections.min(b))).charValue(); char result2 = ((Character)(Collections.min(b))).charValue(); System.out.println(result); System.out.println(result2); } }