/** * Author: Josiah Yoder et al. * User: yoder * Class: SE1011-051 * Lesson: Week 9, Day 1 */ public class Example051_9_1 { /* * This is a scratch-paper method */ public static void main(String[] ignored) { // Swapping Complex051_9_1 c1 = new Complex051_9_1(1,2); Complex051_9_1 c2 = new Complex051_9_1(2,10); c1.swap(c2); // Arrays double topScore1; double topScore2; double topScore3; // Declare array of doubles double[] topScores; // Instantiate an array topScores = new double[5]; // Assign to an array topScores[0] = 4.5; topScores[1] = 4.5; topScores[2] = 3.0; topScores[3] = 2.8; topScores[4] = 4.6; // Alternative initialization approach double[] topScores2 = {4.5, 4.5, 3.0, 2.8, 4.6}; topScores2[4] = 4.8; // Reading values out of an array System.out.println("The 5th annual competition's winner ate the hotdogs in " +topScores[5-1]+ " minutes"); // How to print out all year's scores? // (starting with the first) // Thanks to Rachel for the solution. int i; for(i = 0; i < topScores.length; i++){ System.out.println("The hot dog competition winners ate the hotdogs in " + topScores[i] + " in year " + (i + 1) + "."); } // 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; // do { // //... // }while(); // Can also use with objects. Complex051_9_1[] complexNumbers = new Complex051_9_1[5]; } }