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

struct type salesPerson has a component sales, which is an array of 50 sales totals. Write the command to display the first sales total for a salesPerson variable called janeSmith.

What will be an ideal response?

Computer Science & Information Technology

Which of the following statements is false?

a. The standard deviation is the square root of the variance (in this case, 1.5), which tones down the effect of the outliers. b. The smaller the variance and standard deviation are, the further the data val-ues are from the mean and the greater overall dispersion (that is, spread) there is between the values and the mean. c. The following code calculates the population standard deviation with the sta-tistics module’s pstdev function: statistics.pstdev([1, 3, 4, 2, 6, 5, 3, 4, 5, 2]) d. All of the above statements are true.

Computer Science & Information Technology

Graydon noticed Jack, his friend and classmate, cheating on a physics exam and now he is trying to decide what to do about it. He knows he could keep quiet about it, but that would violate his moral values, plus the school's code of ethics requires students to report incidents of cheating. On the other hand, if he reports the incident, both his friend? and probably all of their other friends will be mad at him. In which phase of the ethical decision-making process is Graydon? 

A. ?gathering information B. ?developing a problem statement C. ?identifying options D. ?weighing options

Computer Science & Information Technology

A(n) ________ is where a peripheral device can attach to a computer so that data can be exchanged between it and the operating system

A) drive B) expansion bus C) port D) slot

Computer Science & Information Technology