Attached are the answers and code for the assignment that was due on 4/27. See the attached files for working source code. (I have also included again a copy of the assignment from 4/27 so you don't have to go back to find it in a prior post.) Most people had the right answers. The most common common mistakes were when people mixed up the value of the index itself of the array with the value at the POSITION of the index. So if the index is 3, arrayName[3] will equal whatever VALUE is stored at INDEX position 3 which is the FOURTH element in the array since the index starts at position 0. In the answer keys attached below, included is the code solution for each problem as well as the answer you should have gotten. I have broken down the code for the individual questions with detailed comments explaining why the lines of code are there. The notes are fairly detailed and I think it should enable you to fix the errors in your program. If you still can not fix your program, email me again with the part on which you are having difficulty. Answers for questions 1 - 5 Question 1. 20 Question 2. 20 Question 3. 22 Question 4. x= 23, y=25 Question 5. x= 21, y=11 Next assignment - Due Friday 5/22/20. 3 parts. 1) If your have not already done so, use the comments and notes in the source code in the attached files below to get your program to work correctly. 2) For problems 6 - 10, change the integer array a from int[a] = new int[10]; to int[a] = {-3,6,9,10,17,19,20,28, 34, 45, 50}; Note this new array a has 11 elements, so if you hard coded your program to loop from index position 0 to 9 (10) elements or in some way wrote your code to assume the array had exactly 10 elements, your code will not work correctly. Review my example to see how and why it will work no matter what the size of array a is. Hint a.length Get the program to work correctly for the new size. 3). Use a random number generator to: a) Create an array a of a random size between 25 and 50 elements (inclusive). b) Use the random number generator to now fill in the array with random integers in the range from -100 to 100 (inclusive). (So if in step 1 you created an array a that has a size of 36, now generate 36 random numbers in the range from -100 to +100, one at a time, (use a loop) and add them into the array a you created in step a). c) Run steps 6 through 10 from the previous assignment on the new array you created. (Add 1 to each element in the array, count the number of negative elements, print the elements in reverse, etc.) d) Use a println statement to make sure your program runs correctly.
Comments are closed.
|
Archives
May 2020
Categories |