Java Self-study note (third day)-while loop-do while loop-for loop-function-function overload

Source: Internet
Author: User

(1) While loop, do While loop: the difference between, while is to first judge the condition, then execute the statement. The Do while is executing the statement first, then judging the condition.

while (loop condition expression) {do{

EXECUTE statement; EXECUTE statement;

}}while (cyclic conditional expression);

(2) for loop:

for (initialize expression; loop condition expression; post-loop action expression) {

Execute the statement;

}

for (int i =0;i<3;i++) {

Execute the statement;

}

(*) While and for small differences, note (the scope of the initialization variable is different)

Class aa{

public static void Main () {

int x=1;

For (System.out.print ("a");x<3; System.print ("C")) {

System.out.print ("D");

x + +;

}

}

}

The printed result is "ADCDC", Print ("C"), executed after the execution of the statement in {}, which is the last statement executed in the entire for loop

for (int a =0,int b=0,int c=0;a<10;a++,b++,c++) Multiple expressions can be separated by commas

Deform for to while

for (int i=0;i<3;i++) {int i=0; int i=0;

} for (;i<3;) {while (i<3) {

i++; i++;

}           }

The simplest form of an infinite loop:

for (;;) {} while (true) {}

Circular Note: Be sure to identify which statements need to participate in the loop and which do not need

Looping through

Accumulate the thought: through the variable record each change result, through the circulation form, carries on the accumulation action.

Counter thought: Number of records

Loop nesting: Playing star exercises, 99 multiplication table (Outer loop control number of rows, inner loop control number of columns)

(*) (statement) break (jump out of loop, terminate Loop), continue (end this loop, continue the next loop)

(*) to label the loop, you can specify (break or Countinue) which loop to work on:

W:for () {

Q:for () {

Break w;//Specifies that a loop that jumps out of W is not identified, and break defaults out of the nearest loop

}

}

The scope of break and countinue

Note that the statements following break and continue do not

Break works on switch and loop, continue only works on loop

(*)//Play star exercises

public static void Main (string[] args)
{
int x=33;
for (int a=0;a< (x+1)/2;a++) {
for (int b=a;b< (x-1)/2;b++) {
System.out.print ("");
}
for (int c=0;c<a*2+1;c++) {//Judging condition is: number of rows *2+1
System.out.print ("*");
}
System.out.println ();
}
for (int a=0;a< (x-1)/2;a++) {
for (int b=a;b>=0;b--) {
System.out.print ("");
}
for (int c=0+ (a*2); c<x-2;c++) {
System.out.print ("*");
}
System.out.println ();
}

}

(function) function = = Method: A standalone applet with a specific function

function format:

The access modifier returns a value type function name (parameter type 1 form parameter 1, parameter type 2 form parameter 2, ...). ){

Execute the statement;

return value;

return for End Function

When there is no return value, the return value type is Void,return keyword can be omitted without writing

Functions cannot be defined, functions can be called from one another, and the function name is directly written to call

Note: Execution statements are not written in class (classes), and execution statements are written in the method body

(*) (function overloading): In the same class, a function with the same name is allowed, as long as their number of arguments is different or the parameter type is different.

The definition of function name should be meaningful, so as to embody function

Overloading of functions, different precedence of parameters, not satisfying implementation overloads

Overloads of the function, regardless of the return value type

Java Self-study note (third day)-while loop-do while loop-for loop-function-function overload

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.