Arrays
This chapter introduces arrays, a common multi-dimensional data structure used to store data of the same type. (Note that a class is a "data type" in this sense.) Arrays have some number of dimensions and a number of elements in each dimension. These are established when the array is created. The range of the array's index in each dimension goes from zero to the number of that dimension's elements minus one. A for loop is commonly used to initialize, manipulate, and access the values in an array. Here, we treat one-dimensional arrays, sometimes called vectors.
12. Several Arrays per Program
Answer:
double[] dvals = { 0.0, 0.5, 1.5, 2.0, 2.5 };
Several Arrays per Program
class ArrayEg4 { public static void main ( String[] args ) { int[] valA = { 12, 23, 45, 56 }; int[] valB = new int[4]; = ; = ; = ; = ; } } |
Question 12:
Fill in the blanks so that the values in valA
are copied into the corresponding cells of valB
.