Rewrite the following for loop using the for each construct


Provide short answers to the following questions in the Big Java textbook. Submit your answers in a text document (plain text or Microsoft Word format, please).

a. Rewrite the following for loop using the "for each" construct to add the length of each String element from the data array to the totalLength.

The strings[] array is an array of String.

int totalLength = 0;
for (i = 0; i < strings.length; i++)
totalLength += strings[i].length;

b. Write a for loop that checks whether two String arrays, strings1[] and strings2[], have the same contents in the same order (be sure to use the .equals() method to compare the contents of the strings), and print a message each time a difference is found.

Assume both arrays are of the same length.

Request for Solution File

Ask an Expert for Answer!!
Computer Engineering: Rewrite the following for loop using the for each construct
Reference No:- TGS02904625

Expected delivery within 24 Hours