Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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
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 ) { // PRINT EACH NUMBER WITH A SPACE AFTER IT System.out.println(); // LEAVE THIS HERE } static int[] trimArray( int[] array, int count ) { return array; // THIS IS NOT CORRECT. YOU MUST REPLACE IT!!!! } // THE CODE IN HERE NOW JUST APPENDS. THIS IS NOT CORRECT static void insertInOrder( int[] arr, int count, int newVal ) { arr[count] = newVal; // THIS IS NOT CORRECT. YOU MUST REPLACE IT!! } }// END LAB #4
Input file
59 82 29 52 60 44 78 93 22 67 76 54 13 77 94 62 100 27 85 35 68 38 55 26 43
Thank you
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started