logo

Crowdly

Browser

Додати до Chrome

// Import the ArrayList class and the Iterator class import java.util.ArrayL...

✅ Перевірена відповідь на це питання доступна нижче. Наші рішення, перевірені спільнотою, допомагають краще зрозуміти матеріал.

// Import the ArrayList class and the Iterator class

import java.util.ArrayList;

import java.util.Iterator;

import java.util.Objects;

public class Main {

public static void main(String[] args) {

// Create an ArrayList - this is a list organized as an array

// add(...) adds a new microorganism to the end of the list

ArrayList<String> microOrganisms = new ArrayList<String>();

microOrganisms.add("Bacteria");

microOrganisms.add("Archaea");

microOrganisms.add("Protozoa");

microOrganisms.add("Algae");

microOrganisms.add("Fungi");

microOrganisms.add("Helminths");

microOrganisms.add("Viruses");

// Get the iterator

// An ArrayList has a method iterator() that returns an iterator, similar to our example in class

Iterator<String> it = microOrganisms.iterator();

// Statement placed here

}

Which statements print out "Helminths" (when entered in method main() after "Statement placed here")?

1) while (it.hasNext()) it.next();

System.out.println(it.next());

2) while (it.hasNext()){

String s = it.next();

if (s.compareTo("Helminths")==0) {

System.out.println(s);

}

}

3) System.out.println(it.next());

4) String s = null;

while (it.hasNext()){

if (it.next().compareTo("Helminths")==0) {

       s = it.next();

break;

}

}

System.out.println(s);

 

Більше питань подібних до цього

Хочете миттєвий доступ до всіх перевірених відповідей на moodle.jku.at?

Отримайте необмежений доступ до відповідей на екзаменаційні питання - встановіть розширення Crowdly зараз!

Browser

Додати до Chrome