/** * Matt Kretchmar * February 28, 2006 * Relay.java * This program computes the accumulated relay times for nations competing * in the 4x100 relay race. * Expected input is n=# of teams followed by n lines each containing * a team name and four relay leg times. */ /** * Matt Kretchmar * March 1, 2006 * Relay.java * This program computes a winner for relay data. */ import java.util.Scanner; class Relay { public static void main ( String [] args ) { Scanner keyboard = new Scanner(System.in); int n; // number of runners // record number of runners System.out.print("Enter number of runners: "); n = keyboard.nextInt(); // store array of names (strings) String names[] = new String[n]; // per each team, store the 4 relay times and then a fifth // spot to hold the total accumulated time double times[][] = new double[n][5]; // read in data and accumulate times for each team for ( int i = 0; i < n; i++ ) { names[i] = keyboard.next(); // each teams accumulated time starts at 0 times[i][4] = 0; for ( int j = 0; j < 4; j++ ) { // read in next leg for this team times[i][j] = keyboard.nextDouble(); // add this leg to the team's total times[i][4] += times[i][j]; } // report team's total System.out.println(names[i] + " time of " + times[i][4]); } } }