Question: /* I'm having trouble figuring out the insertInOrder method. Right now it's printing out all zeroes. I wasn't sure if I wrote my trimArray method

/* I'm having trouble figuring out the insertInOrder method. Right now it's printing out all zeroes. I wasn't sure if I wrote my trimArray method incorrectly or if there's something wrong with the insertInOrder method. Please help */

import java.util.*; import java.io.*;

public class Lab4 { static final int MAX_CAPACITY = 30; // HARDOCED PLENTY BIG. WE'LL DO TRIM AFTER public static void main( String args[] ) throws Exception { if (args.length < 1 ) { System.out.println("usage: $ java Lab3 "); System.exit(0); } int[] arr = new int[ MAX_CAPACITY ]; int count=0; Scanner infile = new Scanner( new File( args[0] ) ); while ( infile.hasNextInt() ) { insertInOrder( arr, count, infile.nextInt() ); ++count; } arr = trimArray( arr, count ); printArray( arr ); // NOTE: NO COUNT PASSED IN }// END MAIN // ############################################################################################################ // MUST USE ENHANCED FOR LOOP IN THIS METHOD // (YOUR TRIM BETTER HAVE BEEN WRITEN CORRECTLY) static void printArray( int[] array ) { for (int eachNum : array) // PRINT EACH NUMBER WITH A SPACE AFTER IT System.out.println(eachNum+" "); // LEAVE THIS HERE } static int[] trimArray( int[] array, int count ) { int[] trimmedArray = new int [count]; for (int i=0;i=0 && newVal

} }// END LAB #4

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!