Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

/* 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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Processing Fundamentals Design And Implementation

Authors: David M. Kroenke

5th Edition

B000CSIH5A, 978-0023668814

More Books

Students also viewed these Databases questions