Question: Need help filling in the missing code /** * Lab 5a * One line description here * 107-x Replace x with section number * 01-Nov-2016
Need help filling in the missing code
/** * Lab 5a * One line description here * 107-x Replace x with section number * 01-Nov-2016 * @author Your Name */ public class Lab5a { public static void main(String[] args) { // System.out.println("Program 5, Your Name, mascxxxx"); // Replace with your name and mascID //-------------------------------------------------------------------------------- //1. Display the value of element 6 of array f //-------------------------------------------------------------------------------- int[] f = {2, 4, 6, 8, 10, 12, 14, 16, 18, 20}; //TODO: Print element 6 of array f System.out.println(); //-------------------------------------------------------------------------------- // 2. Initialize each element of g to 8 //-------------------------------------------------------------------------------- int[] g = new int[7]; for (int i=0; i < g.length; ++i) // TODO: Fill array g for (int i=0; i < g.length; ++i) System.out.println("g[" + i + "] is " + g[i]); System.out.println(); //-------------------------------------------------------------------------------- // 3. Total 100 elements of floating point array c filled with values 1 to 100 //-------------------------------------------------------------------------------- float[] c = new float[100]; double total = 0.0; //TODO: Fill and sum array c System.out.println("Total is " + total); System.out.println("Average is " + (total / c.length)); System.out.println(); //-------------------------------------------------------------------------------- // 4. Copy 11-element array c into the first 11 positions of 34-element array b. //-------------------------------------------------------------------------------- // TODO: create array b and copy c's elements into it for (int i=0; i < b.length; ++i) System.out.print(b[i] + " "); System.out.println(); System.out.println(); //-------------------------------------------------------------------------------- // 5. Determine and print the largest and smallest values contained in 99-element // floating-point array w //-------------------------------------------------------------------------------- Random rand = new Random(1025L); //TODO: Declare array w with 99 elements double min = 5001; double max = -5001; // Filling array w with random numbers between -5000 and +5000 for (int i=0; i < w.length; ++i) w[i] = rand.nextDouble() * 10000 - 5000 ;
// TODO: Find min and max System.out.println("Smallest value is " + min); System.out.println("Largest value is " + max); } }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
