Question

Provide an example of using a for loop without an array.

Provide an example of using a for loop without an array.

Homework Answers

Answer #1
Answer)

It is with the help of the for-each loop one can use the loop without the array:

The syntax is as follows:

for (String tempStr : dataOfArray) {

System.out.println(tempStr);

}

For example as below:

class ConventionalApproach{

public static void main(String[] args) {

String [ ] dataOfArray = {"One" , "Two" , "Three", "Four"};

System.out.println("Use of the conventional approach for loop and array");

for (int a = 0; a < dataOfArray.length; a ++){

System.out.println(dataOfArray[a]);

}

//With the use of for each loop//
System.out.println("With the help of foreach loop");
for (String tempStr : dataOfArray){
System.out.println(tempStr);
}

}

}

Know the answer?
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
Similar Questions
Using Python : without using a for loop Create a 4×5 4 × 5 array ?...
Using Python : without using a for loop Create a 4×5 4 × 5 array ? X with random value. Print out ? X , as well as the largest value of each column.
Using MIPS, make an array of 10 elements. loop so that it multiplies every element by...
Using MIPS, make an array of 10 elements. loop so that it multiplies every element by 4 WITHOUT USING MULTIPLY INSTRUCTION. USE SLL
Using a loop, complete the following method so that it goes through the array from left...
Using a loop, complete the following method so that it goes through the array from left to right, one element at a time and replaces that element with the sum of itself and the next element in the array (if there is a next element). For example, if the input is {1, 3, 5} the output must be {4, 8, 5} -- on the first iteration 1 was replaced by 1+3; on the second iteration 3 was replaced by 3+5....
Given the array below, provide the JS code to loop through the array and print each...
Given the array below, provide the JS code to loop through the array and print each item to the console prepended by "Harry Potter and the " var books = [ "Philosopher's Stone (1997)", "Chamber of Secrets (1998)", "Prisoner of Azkaban (1999)", "Goblet of Fire (2000)", "Order of the Phoenix (2003)", "Half-Blood Prince (2005)", "Deathly Hallows (2007)" ] The console output should be: Harry Potter and the Philosopher's Stone (1997) Harry Potter and the Chamber of Secrets (1998) Harry Potter...
C++ Code! Represent the following matrix using a two-dimensional array and write a nested for loop...
C++ Code! Represent the following matrix using a two-dimensional array and write a nested for loop to initialize the elements (do not initialize the array in the declaration): 10  9   8 7   6   5 4 3   2
1. Now generate y array using the function file my_func for the x array varying from...
1. Now generate y array using the function file my_func for the x array varying from 0 to 4 with an increment of 0.2. Generate x and y arrays without using any loop statement and do not print these arrays. 2. Off of question 1. Using MATLAB plot routine, plot y-array against the x-array generated in question 1. On this plot show grid lines, label the axes as x and y, and write the text ‘y=f(x)’ next to the plotted...
Create an array named data that can store 100 integers. Write a for loop that loops...
Create an array named data that can store 100 integers. Write a for loop that loops 100 times. Inside the loop store the variable you are using to increment the loop into the current element of the array data. So the array data should have a 0 at index 0, a 1 at index 1, a 2 at index 2, ..., a 99 at index 99.
Using an example, describe the process of a somatic reflex loop.
Using an example, describe the process of a somatic reflex loop.
16. Provide an example of a feedback loop from the Cardiovascular System and indicate the various...
16. Provide an example of a feedback loop from the Cardiovascular System and indicate the various components of the homeostatic control mechanism. Be specific. Stimulus: Sensor: Control Center: Effector:
Assume that the inner loop works correctly. Using a loop-invariant proof for the outer loop, formally...
Assume that the inner loop works correctly. Using a loop-invariant proof for the outer loop, formally prove that your pseudo-code correctly sorts the given array. Be sure that your loop invariant and proof cover the initialization, maintenance, and termination conditions Given code: /** * a[0:n-1] is an array of n elements. * temp is a variable to facilitate exchange. */ BubbleSort(a, n) Begin for k = 1 to n-1 increment by 1 do // where, k is for the pass...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT