Having trouble with 2nd //TODO comment. public static ArrayList<Integer> doArray
ID: 3925550 • Letter: H
Question
Having trouble with 2nd //TODO comment.
public static ArrayList<Integer> doArrayListSearchGreatest(int numItems) {
System.out.print("doArrayListSearchGreatest: ");
ArrayList<Integer> list = new ArrayList<>();
// TODO Write code that adds integers 0 through (numitems - 1)
// to list.
for(int i=0; i<=numItems-1; i++){
list.add(i);
}
long startTime = getTimestamp();
// TODO Write code that gets the element at the last index from list.
long endTime = getTimestamp();
long totalTime = endTime - startTime;
System.out.println(totalTime);
return list;
}
Explanation / Answer
public static ArrayList<Integer> doArrayListSearchGreatest(int numItems) {
System.out.print("doArrayListSearchGreatest: ");
ArrayList<Integer> list = new ArrayList<>();
// TODO Write code that adds integers 0 through (numitems - 1)
// to list.
for(int i=0; i<=numItems-1; i++){
list.add(i);
}
long startTime = getTimestamp();
// TODO Write code that gets the element at the last index from list.
int lastElement = list.get(numItems-1);
long endTime = getTimestamp();
long totalTime = endTime - startTime;
System.out.println(totalTime);
return list;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.