Question

What control structure does Java use to process all elements in a collection? A do-while loop....

  1. What control structure does Java use to process all elements in a collection?
    1. A do-while loop.
    2. A for loop.
    3. A for-each loop.
    4. A while loop.
  2. Which of the following is a valid Java array declaration?
    1. String array s[10];
    2. String[] s;
    3. String[10] s;
    4. Array String[] s;
  3. Which of the following references will get the last element in an array of n elements named a?
    1. a[n-1]
    2. a[n]
    3. a[n+1]
    4. a
0 0
Add a comment Improve this question Transcribed image text
Answer #1

1. All elements of a collection can be processed most easily through a for-each loop. However, it is not the best option if these elements need to be altered.

2. The correct syntax is String[] s (if the array is defined without size). It can be declared as String[] = new String[n] for an array of size n.

3. Since the 1st elements of an array is accessed as a[0], the last element can be accessed by a[n-1]

A thumbs-up/up-vote would be greatly appreciated.

Add a comment
Know the answer?
Add Answer to:
What control structure does Java use to process all elements in a collection? A do-while loop....
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
  • write a java program that does the following Part one Use a For loop to compute...

    write a java program that does the following Part one Use a For loop to compute the sum of all the odd numbers from 1 through 99. Your result should be labeled, and the value should be 2500. Print your name 7 times using a While loop. String dogNames[ ] = {"Sam","Buster","Fido","Patches","Gromit","Flicka"}; Using the array defined here, print the values of the array vertically and horizontally using one For-Each loop. Reverse the logic (Nested loops: Indent text) so that the...

  • 7.2.3: Printing array elements with a for loop. Write a for loop to print all elements...

    7.2.3: Printing array elements with a for loop. Write a for loop to print all elements in courseGrades, following each element with a space (including the last). Print forwards, then backwards. End each loop with a newline. Ex: If courseGrades = {7, 9, 11, 10}, print: 7 9 11 10 10 11 9 7 Hint: Use two for loops. Second loop starts with i = courseGrades.length - 1. (Notes) Also note: If the submitted code tries to access an invalid...

  • 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...

  • Write a java program to remove duplicate elements from an array. Do not use Java library...

    Write a java program to remove duplicate elements from an array. Do not use Java library utilities or 3rd party tools to solve this problem. You need to use the “for loop” and manage the index as you traverse thru the array [i ] while looking for duplicates. For example: Example 1 --------------------- Original Array: 105 123 -921 -1 123 8 8 8 -921 Array with unique values: 105 123 -921 -1 8 Example 2 --------------------------- Original Array: 10 22...

  • write in java 1. Assume the availability of a method  named  makeLine that can be passed a non-negative...

    write in java 1. Assume the availability of a method  named  makeLine that can be passed a non-negative integer  n and a character  c and return a String consisting of n identical characters that are all equal to c. Write a method  named  printTriangle that receives two integer  parameters  n and k. If n is negative the method does nothing. If n happens to be an even number, itsvalue is raised to the next odd number (e.g. 4-->5). Then, when k has the value zero, the method prints...

  • In Java write the following array- processing methods into the same application, Lab13.java. Use the main...

    In Java write the following array- processing methods into the same application, Lab13.java. Use the main method in this application to test your methods. 1) Write the void method, shiftLeft, which accepts an array of int and changes the elements of this array so that the index of each element is now less by one and the last element of the array is now zero. For example, if the parameter array is {7, 3, 2, 9, 5}, then when this...

  • What does the following code segment do to the array a[], given that the current_sizevariable holds...

    What does the following code segment do to the array a[], given that the current_sizevariable holds the number of valid elements currently in the array? int element = 0; current_size++; for (int i = current_size - 1; i > pos; i--) { a[i] = a[i - 1]; } a[pos] = element; It shifts all the array elements one position to the left (lower index). It shifts all the array elements one position to the right (higher index). It removes the...

  • QUESTION 1 Using the following declarations and a member of the Array class, int [ ]...

    QUESTION 1 Using the following declarations and a member of the Array class, int [ ] bArray = new int [10]; int location; Using a method in the Array class, write a statement that would change the order of the elements in the bArray array. The contents of the first cell should hold what was in the last cell. The second cell should hold what was in the next to last cell. __________________________ HINT: You must write the full statement...

  • advance java 244 Louis Abe Mujang: Attempt 1 Question 11 (1 point) Write an array declaration...

    advance java 244 Louis Abe Mujang: Attempt 1 Question 11 (1 point) Write an array declaration and allocation that meets the following criteria The array is of type String. The array is named sa. The declaration and allocation should be in the same line of code. The array is allocated to a length of 100 elements. There should be no initializer list. Don't forget the semicolon. 12 Question 12 (1 point) If you declare an array that is 256 elements...

  • Use JAVA language. public class DynamicArray2 { private String[] data; // the backing array private int...

    Use JAVA language. public class DynamicArray2 { private String[] data; // the backing array private int virtualArrayLength; // the number of elements in the dynamic array // Throws an IndexOutOfBoundsException if i is not a valid index // for adding to the dynamic array, otherwise inserts s at index i. // Elements can be added from index 0 to this.size(). public void add(int i, String s) { // If there is no room for s in data, create a new...

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