Take Home Quiz on Arrays

Take Home Quiz on Arrays

<p>Take Home Quiz on Arrays</p><p>True or False? 1. All elements of an array are of the same type. TRUE 2. Array subscripts must be integers. TRUE [SUBSCRIPT] 3. Arrays cannot contain strings as elements. FALSE 4. Arrays cannot use strings as subscripts. TRUE</p><p>For each of the following sets of values, write code that fills an array, A, with the values. Use a loop when appropriate.</p><p>5. 1 2 3 4 5 6 7 8 9 10 int [] A = new int[10]; for (int j = 0; j<A.length;j++) A[j] = j +1; 6. 0 2 4 6 8 10 12 14 16 18 20 int [] A = new int[11]; for (int j = 0; j<A.length;j++) A[j] =j*2;</p><p>7. 1 4 9 16 25 36 49 64 81 100 int [] A = new int[10]; for (int j = 0; j<A.length;j++) A[j] =(j+1)*(j+1);</p><p>8. 0 0 0 0 0 0 0 0 0 0 int [] A = new int[10];</p><p>9. 1 4 9 16 9 7 4 9 11 int [] A = {1,4,…..} What is wrong with the following loop? Explain 2 ways of fixing the error. 10. double[] data = new double[10]; for(int j = 0; j <10; j++) data[j] = j * j;</p><p>11. What statement actually reserves the memory locations for an array? new 12. The statement int[]value = new int[34]; reserves memory for how many integers? 34</p><p>13. If you declare an array as int[]num = new int[6]; the last element of the array is printed by what statement? SOP(num[5]); OR SOP(num[num.length – 1])</p><p>Assume you declared an array as int[] num = {101,202,303,404,505,606}; 14. What is the element stored at num[3]? 404 15. What is the element stored at num[0]? 101</p><p>16. What is the element stored at num[6]? Out of bounds exception 17. Assume an array is declared as int[]num = new int[4]; Write a for loop that correctly assigns the value 100 to each of the 4 array elements? for (int j = 0; j<num.length;j++) num[j] = 100;</p><p>18. Define an array x, that stores 5 integers. int [] x= new int[5];</p><p>19. Define an array y, that stores 10 characters. char [] y = new char[10]</p><p>20. Define an array z, that stores 20 strings and sets the first element of the array to “Computer Science is fun”. String [] z = new String [20]; z[0] = “computer science is fun”;</p>

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    3 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us