Recently, jdk1.4.2 and eclipse3.0.1 are installed on the machine. Eclipse is really easy to use, especially the parameter prompt function. There are still a lot of Java resources on the Internet. I read the first few chapters in the Chinese version of thinking in Java. Here are some of the issues and findings: 1. A problem with the For Loop For (INT I = 1, j = I + 10; I <5; I ++, j = I * 2) System. Out. println ("I =" + I + "J =" + J );Running result: I = 1 J = 11 I = 2 J = 4 I = 3 J = 6 I = 4 J = 8 After a few changes: For (INT I = 1, j = I + 10; I <5; I ++ ){ J = I * 2; System. Out. println ("I =" + I + "J =" + J ); } The result is: I = 1 J = 2 I = 2 J = 4 I = 3 J = 6 I = 4 J = 8 After asking for help on the internet, I found that the reason is: after the for loop executes the conditional test, it executes the program part first, and then it is just a step. 2. Use break and continue to add labels In Java statements, the only place where labels can be placed is in front of the loop statement. In addition, there cannot be anything between the loop statement and the tag. Label1: Outer-iteration { Inner-iteration { //... Break; // 1 //... Continue; // 2 //... Continue label1; // 3 //... Break label1; // 4 } } Case 1 will interrupt the internal loop. 2. It will interrupt the current internal cycle and directly jump into the next cycle. Case 3 breaks the internal and external loops, jumps to label1, and starts the loop again from the external beginning. Case 4 jumps to label1. The following is an example: Public class labeledfor { Static Test monitor = new test (); Public static void main (string [] ARGs ){ Int I = 0; Outer: // cant have statements here For (; true;) {// Infinite Loop Inner: // cant have statements here For (; I <10; I ++ ){ System. Out. println ("I =" + I ); If (I = 2 ){ System. Out. println ("continue "); Continue; } If (I = 3 ){ System. Out. println ("break "); I ++; // otherwise I never // Gets incremented. Break; } If (I = 7 ){ System. Out. println ("Continue outer "); I ++; // otherwise I never // Gets incremented. Continue outer; } If (I = 8 ){ System. Out. println ("break outer "); Break outer; } For (int K = 0; k <5; k ++ ){ If (k = 3 ){ System. Out. println ("Continue inner "); Continue inner; } } } } } }///:~ Result: "I = 0 ", "Continue inner ", "I = 1 ", "Continue inner ", "I = 2 ", "Continue ", "I = 3 ", "Break ", "I = 4 ", "Continue inner ", "I = 5 ", "Continue inner ", "I = 6 ", "Continue inner ", "I = 7 ", "Continue outer ", "I = 8 ", "Break outer"
Article: Western Digital-professional domain name registration and virtual hosting services Http://www.west263.com The above information is an integral part of the text. If you want to reprint this article, please keep the above information. Thank you! |