How can you use the enhanced for loop?

What will be an ideal response?

You can use the enhanced for loop to cycle through an array of objects. For example, to display data for seven Employees stored in the emps array, you can write the following:?for(Employee worker : emps)   System.out.println(worker.getEmpNum() + " " + worker.getSalary();?In this loop, worker is a local variable that represents each element of emps in turn. Using the enhanced for loop eliminates the need to use a limiting value for the loop and eliminates the need for a subscript following each element.

Computer Science & Information Technology

You might also like to view...

Documents created with multiple columns often used justified text where the left and right margins of the columns of the text are aligned

Indicate whether the statement is true or false

Computer Science & Information Technology

A MAC address contains 32 digits

Indicate whether the statement is true or false

Computer Science & Information Technology