Advertisement
JackHoughton00

Chapter 10 Written Work

May 18th, 2017
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.25 KB | None | 0 0
  1. 1a) Each element has an index value, with 0 being the index of the first item, 1 the index of the second item, and so on.
  2. 1b) An array must be declared and then space allocated for the elements of the array. The declaration includes the type followed by brackets ([]) to indicate an array.
  3. 1c) Initializing an array means that a value is given for each element.
  4. 1d) A run-time error is generated when an invalid index is used. For example, the exception ArrayIndezOutOfBoundsException is thrown when the following statement tries to execute:
  5. friends[5] = “Wilbur”; //ERROR! Generates an exception.
  6. 1e) Accessing each element of an array is called traversing an array.
  7. 1f) Sometimes referred to as a for-each statement, the following statement displayed each element in the array:
  8. for (String element : friends) {
  9. System.out.println(element);
  10. }
  11. The statement above displays the name in array one after the other.
  12.  
  13. 3. Example, the approach for a range of years 1900 through 2000 wold require an array of 2001 elements with only the last 100 elements in use. For ranges such as these, the solution is to store counters at offset array indexes. For example, for an outcome of 1900, a counter at index 0 would be incremented for an outcome of 1901, a counter at incase 1 would be incremented, and so on.
  14.  
  15. 5a) The value returned by the charAt() method is a char data type. A char data type represents a single character, such as a letter or symbol.
  16. 5b) The toCharArray() method converts each character in the string to a char and then assigns it to the appropriate element in an existing char array.
  17. 5c) Letters of every alphabet and symbols of every culture have been given a representation in a digital code called Unicode. Unicode uses a set of sixteen 1s and 0s to form a sixteen-bit binary code for each symbol.
  18.  
  19. 8a) The length property can be used to determine the number or rows and columns in a two-dimensional array with who separate statements:
  20. rows = tttBoard.length;
  21. cols = tttBoard[0].length;
  22. 8b) An element of a two-dimensional array is accessed by including the indexed of the row and column in brackets after the array name. For example, the following statement assigns the element in the second row, third column the letter “X”;
  23. tttBoard[1][2] = “X”;
  24. 10a) A collection is a group of related objects, or elements, that are stored together as a single unit. An array is an example of a collection.
  25. 10b) A dynamic array varies in size during run time and is used in application where the size of an array may need to grow or shrink.
  26. 10c) The Integer and Double classes provided with Java, are used to “wrap” primitive values in an object. The integer and Double wrapper classes include the methods for comparing objects and for returning the value stored by the object as a primitive.
  27.  
  28. True False
  29. 13a) True
  30. 13b) True
  31. 13c) True
  32. 13d) False, they automatically go to null.
  33. 13e) True
  34. 13f) True
  35. 13g) False, it can search an entire array if the thing it is searching for isn't in the array.
  36. 13h) False, 16.
  37. 13i) False, lowercase letters have the higher base 10 number values.
  38. 13j) False, you cannot change the size of an array after it has been made.
  39. 13k) True
  40. 13L) True.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement