The method of implementing the filter of the loop body in Java _java

Source: Internet
Author: User

Write the program, use the continue statement to implement the Loop body filter, filter the "Eagle" string, and do the appropriate processing, but discard all the code after the continue statement. Where encounters the eagle string for specific processing, and then skips general processing with the continue statement.

Copy Code code as follows:

public class Continue {
public static void Main (string[] args) {
string[] array = new string[] {"Egret", "Red-crowned Crane", "Oriole", "Parrot", "Crow", "Magpie",
"Eagle", "cuckoo", "Eagle", "Gray-Grain Bird", "Eagle", "Lark"};
SYSTEM.OUT.PRINTLN ("There are many birds in my garden, but recently a few eagles, please help me take them away.") ");
int eaglecount = 0;
for (String String:array) {//foreach traversal array
if (String.Equals ("Eagle")) {//If you encounter an eagle
System.out.println ("Found an eagle, has caught the cage.") ");
eaglecount++;
continue;//Interrupt Loop
}
System.out.println ("Search for birds, found:" + string);/otherwise output array element
}
System.out.println ("Caught" altogether: "+ Eaglecount +" only eagle. ");
}
}

The effect is as shown in the figure:

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.