Question

Suppose a is an array of values of type double that is partially filled. The array...

Suppose a is an array of values of type double that is partially filled. The array contains meaningful values in only the first numberUsed elements. where numberUsed is a variable of type int. Write some java code to display all the meaningful values in the array a.

0 0
Add a comment Improve this question Transcribed image text
Answer #1
public class PrintPartialArray {

    public static void main(String[] args) {
        double[] a = new double[10];
        a[0] = 5.5;
        a[1] = 4.7;
        a[2] = 9.1;
        a[3] = 3.0;
        int numberUsed = 4;

        for (int i = 0; i < numberUsed; i++) {
            System.out.println(a[i]);
        }
    }
}
Add a comment
Know the answer?
Add Answer to:
Suppose a is an array of values of type double that is partially filled. The array...
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
  • Suppose v is an array with 100 int elements. If 100 is assigned to v[100], what happens? Show the code. An array of 1000 integers is declared. What is the largest integer that can be used as an index...

    Suppose v is an array with 100 int elements. If 100 is assigned to v[100], what happens? Show the code. An array of 1000 integers is declared. What is the largest integer that can be used as an index to the array? Shows the code. Consider the declaration: int v[1]; What is the index of the last element of this array? Declare an array named a of 10 int elements and initialize the elements (starting with the first) to the...

  • 9. Write some C++ code that will fill an array a with 20 values of type...

    9. Write some C++ code that will fill an array a with 20 values of type int read in from the keyboard. You need not write a full program, just the code to do this, but do give the declarations for the array and for all variables. 10. Suppose you have the following array declaration in your program: int your_array[7]; Also, suppose that in your implementation of C++, variables of type int use two bytes of memory. When you run...

  • Using C++ Insert elements into a partially filled array. a) Create a partially filled array of...

    Using C++ Insert elements into a partially filled array. a) Create a partially filled array of CAPACITY 100. b) Initialize the array with values 10,20,30,40,50,60,70,80,90,100 c) Create a print function for the array. d) Create an insert function which inserts an integer into the array in sorted position. e) Insert the numbers 5, 150 and 55. f) Print the array before and after each insertion. Output Example 10 20 30 40 50 60 70 80 90 100 5 10 20...

  • 1.Write code for a Java method, printArray, that takes an int array as parameter and prints...

    1.Write code for a Java method, printArray, that takes an int array as parameter and prints it out, one element per line. public static void printArray (int[] values){ Methods that do NOT return a result have “void” as return type. Notice how an array parameter type is passed, int [] }// end printArray 2.Write code for a Java method that takes in as input parameter an integer number, say num, and returns a double array of size num with all...

  • Write a java class, MaxHeap, to implement a max-heap of values of type double. Use an...

    Write a java class, MaxHeap, to implement a max-heap of values of type double. Use an array and be prepared to grow the array. The array implementation will probably be more efficient. Next, write three java sorting methods: a) One should be the heapsort algorithm. b) the second should sort the array by inserting all the elements from the array into a heap defined by the MaxHeap class, and then removing all the items from the heap and putting them...

  • JAVA: Suppose you have the following array declaration and initialization:      int [ ] values;     ...

    JAVA: Suppose you have the following array declaration and initialization:      int [ ] values;      values = new int[18]; Suppose there is a static method called sumAll that is sent an integer array. The sumAll method computes and returns the sum of all the integers in the array that it is sent (assuming the array is filled). Choose the best example of calling this method: Group of answer choices a) sumAll( values[0], values.length ) b) sumAll( values[0 .. 17]...

  • a) Declare and instantiate an array named scores of twenty-five elements of type int.   (b)Write a...

    a) Declare and instantiate an array named scores of twenty-five elements of type int.   (b)Write a statement that declares an array namedstreetAddress that contains exactly eighty elements of typechar. 2. In a single statement: declare, create and initialize an arraynamed a of ten elements of type int with the values of the elements (starting with the first) set to 10, 20,..., 100 respectively. 3. Declare an array reference variable, week, and initialize it to an array containing the strings "mon",...

  • JAVA Write a static method that takes an array of a generic type as its only...

    JAVA Write a static method that takes an array of a generic type as its only argument. The method should display the array and return the number of elements in the array. Test the method in main with at least three arrays of objects. SAMPLE OUTPUT Here is an Integer array 12 21 7 16 8 13 That array held 6 elements Here is a String array one two three four That array held 4 elements Here is a Double...

  • Refer to the following array definition for questions 1 & 2 int numberArray[9)[11] 1. Write a...

    Refer to the following array definition for questions 1 & 2 int numberArray[9)[11] 1. Write a statement that assigns 145 to the first column of the first row of this array. 2. Write a statement that assigns 18 to the last column of the last row of this array. values is a two-dimensional array of floats, with 10 rows and 20 columns. Write code that sums all of the elements in the array and stores the sum in the variable...

  • Write a java code that Declares and initialize a two-dimensional int array named grades. It should...

    Write a java code that Declares and initialize a two-dimensional int array named grades. It should have 10 rows and 6 columns where it stores the values and then calculates the average of all the elements in the grades array that you have declared

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