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

  • QUESTION 39 ____ is NOT an iterative control structure. a. A while loop b. A do...while...

    QUESTION 39 ____ is NOT an iterative control structure. a. A while loop b. A do...while loop c. A for loop d. Recursion QUESTION 49 : Consider the program below: public class Test { public static void main( String[] args )    {       int[] a;       a = new int[ 10 ];       for ( int i = 0; i < a.length; i++ )          a[ i ] = i + 2;       int result = 0;       for (...

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

  • 1. What does a Java compiler do? Select one: a. Runs Java programs b. Translates byte...

    1. What does a Java compiler do? Select one: a. Runs Java programs b. Translates byte code in ".class" files into machine language c. Translates source code in ".class" files into machine language d. Translates source code in ".java" files into Java byte code in ".class" files e. Translates source code in ".java" files into machine language 2. A subclass will _____ one superclass. Select one: a. abstract b. extend c. implement d. inherit e. override 3. Consider the following...

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

  • Write a for loop to print all elements in courseGrades, following each element with a space...

    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) Note: These activities may test code with different test values. This activity will perform two tests, both with a...

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