Java for Loop

Source: Internet
Author: User

PublicclassTest2 {StaticBooleanFooCharc) {System. out. print (c);returntrue; } PublicStaticvoidMain (string[] argv) {inti = 0; For (65;88&& (I&LT;2); 67) for(Foo(' A ');Foo(' B ') && (I < 2);Foo(' C ')) {i++;Foo(' D '); }}}/*what is the result? A. ABDCBDCBB. ABCDABCDC. Compilation fails. D. An exception are thrown at runtime.//output is: ABDCBDCB Analysis: The conditions in the For loop to be true, and your judgment is nothing like here, although it is printed letters, but not false, So it is possible to perform the first loop: foo (' a ') prints the letter A, (note: This is the default true condition) foo (' B ') prints the letter b,i=0, compares (I < 2), the condition is true, the loop body, foo (' D ') prints Dfoo (' C ') print the letter C the second cycle: foo (' B ') print B,i=1, compare (I < 2) to true, perform loop body, foo (' D ') print Dfoo (' C ') print letter C third loop: foo (' B ') print letter b,i=2, compare (I < 2) to False, exit the loop, get the result */

Java for Loop

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.