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 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
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:
Please, write a loop to print even numbers of an array a with pointers. You can...
Please, write a loop to print even numbers of an array a with pointers. You can use a variable “size” for array size
write a loop to print an array a with pointers backwards. You can use a variable...
write a loop to print an array a with pointers backwards. You can use a variable “size” for array size. write you code in C
A programmer that you work with, Peter, is a jerk. He is responsible for an array...
A programmer that you work with, Peter, is a jerk. He is responsible for an array that is a key part of an important program and he maintains a sum of the array value.He won't give you access to this array; however, your boss has told you that you need to get input from the user and then place it into the array.Each evening Peter will scan the code and remove any illegal references to his array. Using pointers, access...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT