Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I need help with this java program. an array is created and filled with int that the user enters. an upsize method is created to

I need help with this java program. an array is created and filled with int that the user enters. an upsize method is created to allow all of the ints to fit in the array. now i have to create a downsize method which will remove the empty space in the array. please help.
image text in transcribed
image text in transcribed
9:05 PM Sun Feb 28 78% 11 2 We will use this tab to expand our acilities with arrays and serve as an intro to methods. Aethod is a way to move code out of main to callable 3 Location where the section of code can be called From anywhere within your program. Aethod can directly call to any other dethod to the class 4 Two methods are already complete and accessible to be called, printArray and upsize: 5 Asethod s 2 parted, a definite which will contain what valves (arguments) can be sent toto the method for it to use and att commands it performs 6 AND the CALL to the thod. The call will activate that method. 7 The arrays will be the main focus in the lab. We will need to overcome one of the oldest Lition of arrays in Java, their immutability of size. & Arrays CANNOT change their size after being declared, 30 we are loited in our ability to use thes, too small or too lange will always be our problee 9 work smartert Java want allow the array sell to change, we need to go around the rules instead of breaking the Java allows a nace of array to watch 10 targeted addresses in memory, meaning are Duttslight of Mand on java and switch the age of the array to a different array it won't know the difference 11 We have an ipsa ze method already built woich will take an existing array in. It wilt double the zefsee lecture vid for an explanation wy) 12 I create an array double the size of the current array, it will then copy over all values for the original array into the larger one - then give it bac 13 printArray sethod wall go through a wole array and output all of its values to the interface. 14 15 Nission for LabG: Build out the downsize method at the bottom of the source. We dont want extra empty spaces in our array by the end. Its-netficient and 16 potentially a problem if we use that array as datasource for other purposes. 1? What to hand In? Java scorce file. Also, run the program and give it 3 values only. Sow the results of the pritarray on the command Line. Then 18 give it enough values to require at LEAST 1 wize 19 Make sure you arent seeing trating zeros which would nescate ampty places in the array. If you give its values(say 1,2,3,4,5) your owtput should look like 2012345 21 > The amount of values in the arrays that we care about 15: 5 22 NOT 23-12345 52 count ! this increments the number of values in the array 53 54 3 55 56 //place call to downstre here seed to send to the array to date AND the court, count tells the downsize the needed size 57 printArray(myarray): 58 System.out.println("The amount of values in the arrays that we care about 1s: + count); 59 3 GO ipsize merhad with take the arrays current size and double dt. Why do to 61 static int upsizel intil array) 62 intlbigger = new int[array.Length 21: 63 for (int i =; icarray.length; i++) 64 bigger[1= array[il: 65 66 return bigger: // the address in memory for this array will return back from the method and replace the address listed for the original 67 > 68 Marantaray method Alleycle through every value of an array and print it out to the command Lineterminal 69 static void printArray Intll array 70 71 for (int number array Wenhance for loop, operator is the set operator" 72 System.out.printl number + " "): 73 System.out.println(); 74 notice there is no return Meret vosd means no datatype for return. cara itt come out of this method, its a one way trip 75 76 W You will need to build the downsize method to eliminate unused space in the array from the size operation. 77 Static Intll downsize(int Il array, int count) 78 W create your new seatter array based on the count size 79 // wse looptike size did, however, your test coodation can NOT be based on array.Length se 11 inside the loop 81 return array:// this is only here to allow your code to compete, 10 is not a proper downsized array Replace with your smaller arres 82 83 84) TAB ? @ U

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

Professional SQL Server 2012 Internals And Troubleshooting

Authors: Christian Bolton, Justin Langford

1st Edition

1118177657, 9781118177655

More Books

Students also viewed these Databases questions