Question

Arrays 1 a) What field does every array object have? b) Suppose you have this code:  double[...

Arrays

1

a) What field does every array object have?

b) Suppose you have this code:  double[   ] temperatures = new double[12];

Write the lines of code to triple the capacity of the array

0 0
Add a comment Improve this question Transcribed image text
Answer #1

a) What field does every array object have?

Answer: Every array in java contain a final field that is length. length is the property that will give the number of elements in array.

b) Suppose you have this code:  double[   ] temperatures = new double[12];

Write the lines of code to triple the capacity of the array

Answer:

     double[ ] temperatures = new double[12];

   temperatures = Arrays.copyOf(temperatures , temperatures.length * 3);

Add a comment
Know the answer?
Add Answer to:
Arrays 1 a) What field does every array object have? b) Suppose you have this code:  double[...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • For Computer Organization and Design: Suppose we have 3 arrays A, B, and C, array A’s...

    For Computer Organization and Design: Suppose we have 3 arrays A, B, and C, array A’s base address is in $S3, B’s base address is in $S4, C’s base address is in $S5. You can only use two temporal registers $t0 and $t1. Convert the following code into MIPS assembly language code. Suppose every array element occupies 1 word in MIPS (32 bits). A[20] = B[0] + C[6] - 1

  • I need help with some java code concerning the comparison of two arrays. Let's say I...

    I need help with some java code concerning the comparison of two arrays. Let's say I have two arrays. Array A and Array B. Array A has 7 integers on each line, and there are hundreds of lines. Array B is the same as Array A except every line of integers have been sorted in ascending order. In Array A there are already lines that are sorted, so some lines in Array A will be equal in Array B. What...

  • Q1) How would you declare an array of doubles called myDoubles? Arrays can be initialized in...

    Q1) How would you declare an array of doubles called myDoubles? Arrays can be initialized in one of two ways. In one method, the array elements are placed in a list enclosed in curly braces after the array name definition. For example, the code below creates an array of ints with 3 elements: 1, 2 and 3. int[] a = {1, 2, 3, 4}; We can also initialize an array with a new construct, indicating how many elements we want...

  • IN C++ ADD COMMENTS AS MUCH AS POSSIBLE Exercise 1: Duplicate the Arrays Suppose you are...

    IN C++ ADD COMMENTS AS MUCH AS POSSIBLE Exercise 1: Duplicate the Arrays Suppose you are developing a program that works with arrays of integers, and you find that you frequently need to duplicate the arrays. Rather than rewriting the array-duplicating code each time you need it, you decide to write a function that accepts an array and its size as arguments. Creates a new array that is a copy of the argument array, and returns a pointer to the...

  • Parallel Arrays Summary In this lab, you use what you have learned about parallel arrays to...

    Parallel Arrays Summary In this lab, you use what you have learned about parallel arrays to complete a partially completed Java program. The program should either print the name and price for a coffee add-in from the Jumpin’ Jive coffee shop or it should print the message: "Sorry, we do not carry that.". Read the problem description carefully before you begin. The data file provided for this lab includes the necessary variable declarations and input statements. You need to write...

  • 3. Suppose you have an array of n random elements. You are required to perform n...

    3. Suppose you have an array of n random elements. You are required to perform n different searches on the array. What is best big-oh time for your entire task? Explain how to achieve that time. 4. Suppose you are given two sorted integer arrays int[] A and int[] B. Write a method that returns an array which contains only the common elements (elements that are present in both A and B) of these two sorted arrays. Indicate the big-Oh...

  • please explain. Thanks in advance Dynamic Arrays Revisited (40 points) A dynamically re-sizing array is an...

    please explain. Thanks in advance Dynamic Arrays Revisited (40 points) A dynamically re-sizing array is an array that is initially allocated at size 1. and every time you need to insert past the end of the array you double its size and copy elements from the old array to the new array. In class, we showed that n inserts into a dynamic array can be accomplished in O(n) using an accounting argument where we pre-paid $3 for each insert, thus...

  • using matlab In Class Exercises 8-Arrays For the following exercises, assume an array is already populated, your job is to write a program that traverses the array. DO NOT HARD CODE the last in...

    using matlab In Class Exercises 8-Arrays For the following exercises, assume an array is already populated, your job is to write a program that traverses the array. DO NOT HARD CODE the last index. In other words, you code for 1-4&6 should be able to handle the following 2 arrays: amp2 10 array1 [52, 63, 99, 71, 3.1] array2 - [99:-3: 45); For 5: wordArray1 wordArray2 ('number, 'arrays', 'indices', 'hello', finish' [number, 'different, 'finish? 1. Determine the sum of all...

  •     (10 pts) Define a two-dimensional array named temp with three rows and four columns of type int such that the first...

        (10 pts) Define a two-dimensional array named temp with three rows and four columns of type int such that the first row is initialized to 6, 8, 12, 9; the second row is initialized to 10, 13, 6, 16; and the third row is initialized to 27, 5, 10, 20.     (10 pts) Consider the following declarations, and see p.566: enum brands = { GM, FORD, TOYOTA, BMW, KIA }; const int N_BRANDS = 5; const int COLOR_TYPES = 6; double...

  • java (data structures) 8) Suppose you have the following code: :ArrayOrderedList myL = new ArrayOrderedList( );...

    java (data structures) 8) Suppose you have the following code: :ArrayOrderedList myL = new ArrayOrderedList( ); Iterator it = myL.iterator( ); //answer the following questions: a) What does the method, iterator( ) return? b) According the use above, where is this iterator( ) method written? c) Write the lines of code (loop) to print all the Student data in the ordered list using the iterator, it.

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT