Write a program, use the continue statement to implement a loop filter, filter the "eagle" string, and do the corresponding processing, but give up all code after the continue statement. That is, if you encounter a "eagle" string, you will perform specific processing, and then use the continue statement to skip the general processing.
The code copy is as follows:
public class Continue {
public static void main(String[] args){
String[] array = new String[] { "Egret", "Red-crowned Crane", "Original", "Parrot", "Crow", "Magpie",
"Eagle", "Cuckoo", "Eagle", "Gray-patterned Bird", "Eagle", "Lag" };
System.out.println("There are many birds in my garden, but a few eagles have come recently, please help me catch them.");
int eagleCount = 0;
for (String string : array) {// foreach traverses the array
if (string.equals("Eagle")) {// If you encounter an eagle
System.out.println("A eagle was found and has been caught in the cage.");
eagleCount++;
continue;// interrupt the loop
}
System.out.println("Search for birds, found: " + string);// Otherwise, output array elements
}
System.out.println("Catched in total:" + eagleCount + "Eagle.");
}
}
The effect is shown in the figure: