Advertisement
detroitdayne

Chapter 7 review questions

Nov 15th, 2014
177
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.14 KB | None | 0 0
  1. R7.1    a) double[ ] values = new double[10];
  2.             Double[ ] moreValues = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
  3.        
  4.         b) double[ ] values = new double[11];
  5.             Double[ ] moreValues = {0, 2, 4, 6, 10, 12, 14, 16, 18, 20};
  6.        
  7.         c) double[ ] values = new double[10];
  8.             Double[ ] moreValues = {1, 4, 9, 16, 25, 36, 49, 64, 81, 100};
  9.        
  10.         d) double[ ] values = new double[10];
  11.             Double[ ] moreValues = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
  12.  
  13.         e) double[ ] values = new double[9];
  14.             Double[ ] moreValues = {1, 4, 9, 16, 9, 7, 8, 9, 11};
  15.        
  16.         f) double[ ] values = new double[10];
  17.             Double[ ] moreValues = {0, 1, 0, 1, 0, 1, 0, 1, 0, 1};
  18.  
  19.         g) double[ ] values = new double[10];
  20.             Double[ ] moreValues = {0, 1, 2, 3, 4, 0, 1, 2, 3, 4};
  21.  
  22. R7.2    26
  23.  
  24. a)      36
  25. b)      38
  26. c)      39
  27. d)      38
  28. e)      38
  29. f)      35
  30. g)      36
  31. h)      36
  32.  
  33. R7.3    26
  34.  
  35. a)      26
  36. b)      34
  37. c)      35
  38. d)       35
  39. e)      36
  40. f)      36
  41. g)      31
  42. h)      30
  43.  
  44. R7.4    final int LENGTH = 100;
  45. double[] values = new double[LENGTH];
  46.  
  47. int currentSize = 0;
  48. Scanner in = new Scanner(System.in);
  49. while (in.hasNextDouble())
  50. {
  51.  if (currentSize < values.length)
  52.  {
  53.  values[currentSize] = in.nextDouble();
  54.  currentSize++;
  55.  }
  56. }
  57.        
  58. R7.6 a) the values[i] = i * i
  59.         b) the < values.lenght; i++)
  60.  
  61. R7.11 An array is a data structure consisting of a collection of elements (values or variables), each identified by at least one array index or key. Are index values that are legal to use in the programming. Bounds error are errors with the using of arrays and how its is not correct to use.
  62.  
  63. R7.23 you have to list the number where to go by like 1 to 100.
  64.  
  65. R7.28  
  66.  
  67. double[][] b = new double[3][];
  68.  
  69. for (int i = 0; i < b.length; i++)
  70. {
  71.  b[i] = new double[i + 1];
  72. }
  73.  
  74. for (int i = 0; i < b.length; i++)
  75. {
  76.  for (int j = 0; j < b[i].length; j++)
  77.  {
  78.  System.out.print(b[i][j]);
  79.  }
  80.  System.out.println();
  81. }
  82.  
  83. for (double[] row : b)
  84. {
  85.  for (double element : row)
  86.  {
  87.  System.out.print(element);
  88.  }
  89.  System.out.println();
  90. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement