while loop && [Methods]


while loop:
while loop: loop condition
for the number of cycles: determining a change in the variable range, and the number of cycles
can be used for the can while

initial conditions;
while (determination condition) {
loop statement;
condition change;
}
// find a and between 100 ~
// for loop
int sum = 0;
for (int I =. 1; I <= 100; I ++) {
SUM = I +;
}
System.out.println (SUM);
// whlie cycle
sum = 0;
int m =. 1; // initialization condition;
the while (m <= 100) {
SUM + = m;
m ++; // condition changes
}
do {
} the while ();
do.while cycling
conditions initialization;
do {
loop statement ;
condition change;
} while (conditional);
regardless of whether the condition is satisfied, at least in order to execute
if the condition is not used while and do..while difference condition is not satisfied, will certainly executed once do..while
example:
do {
System.out.println ( "regardless of whether the condition is satisfied, at least in order to execute");
} the while (to false);
BREAK and continue the difference and effect;
BREAK and continue differences:
BREAK
application scenario: may be used in the loop switch and
effect: end switch, the end of the cycle
continue
scenarios: use only in a loop
effect: the end of this cycle, direct access to the next cycle

Number 3 or 3 encountered between multiple //1.1~10 skipped
for (int I =. 1; I <= 10; I ++) {
IF (I% 3 == 0) {
Continue;
}
the System.out .println (I);
}
. 5 th number divisible by 3 of between 1 and 100 before printing @
int COUNT = 0;
for (int I = 1; I <= 100; I ++) {
IF (I 3% 0 ==) {
System.out.println (I);
COUNT ++;
IF (COUNT ==. 5) {
BREAK;
}
}
}
method:
block processing function

requirements:
1. the method does not call does
2. the method can only defined outside the class method, the method can not be nested in the method

defined:
there are a method return type
modifiers return type method name ([parameter list]) {
processing block functions;
return value return;
}
modifier: access modifiers, the default public static
return value type: method of calculation required to get results, defined as the return type of the method, the results of the data class
type written here
may be the basic data types | reference data types
Method name: identifier -> naming identifiers | specification
calling a method method
() -> list of parameters: parameters can be no argument, can have multiple parameters
during the execution process, if there is no unknown variable determines the
data type of the variable name 1, variable name 2 ... data type
can be a basic data type | reference data type
parameter corresponding to declare a local variable -> method is only valid in the current scope defined in
{} - -> solution block function
return: 1) early termination method 2) with a return value (return to caller to the return value of the method)

does not return a value of type

called method: method name ([parameters]); - > code execution method
1) Common name calling method ([parameters]);
2) data call type variable name assignment method name = ([parameters]);
3) outputs the call System.out.println (method name ([parameter ]));


parameters:
formal parameters: in case of process () parameters (parameters)
actual parameters: a method call value (argument in ())
arguments and parameters correspond to
the number, data type , the same sequence of

method can improve reusability of code
is a class encapsulated embodied
pu static void main BLIC (String [] args) {
//. 1, the ordinary call
getPI (); // this method executes code
// assignment 2 call.
getPI D = Double ();
System.out.println (D);
.. 3 outputs the call //
System.out.println (getPI ());

System.out.println (GetSum (3,5));

}

// definition of a function return pi
// return value: double required parameters: parameter no
// the return value of the method has no parameters
public static double getPI () {
System.out.println ( "method without parameters return value");
3.141592653 return;
}

// find the two numbers and
// returns: int parameters to: require two a parameter of type int int, int B
// return value and parameters of the method
public static int getSum (int a, B int) {
System.out.println ( "methods have return value parameter");
return a + B;
}
method call:
value type of method does not return
modifier void method name ([parameter list]) {
method body statement;
[return;]
}

void: no return value
return: early termination method of

Calling the method: the method name ([parameters]); -> executed code in the method
1. Ordinary call
return and role unreachable statement
return:
only be used in the method
has a return value: 1) early termination method 2) with the return value
does not return value: 1) early termination method

is unreachable statements:
1. can not be defined in the back of a return will execute the contents of
the statement back 2.break
back 3.continue statement
4.while (false) in content
content the infinite loop back

compatible types:
1. parameter: parameter> = actual parameter data type
data is returned after the return data type <value type = method <= variable receives the return value: 2. return value type
method overloading:
overloaded methods
in a class, there are a plurality of methods, the same method name, a list of the different parameters | different method signature
method signature: method name parameter list + -> uniquely identify the process

requirements:
1. the same a class
in the same manner a plurality of process names 2.
3. the parameter list different
number of different parameters
of different data types of parameters
of different types of data in different order parameters

overloading and modifiers independent methods
overloaded methods return values regardless of the presence or absence and
overloaded methods Irrespective of the type of the return value
Parameter names overloading and independent

overloaded method invocation:
according to different parameters matching method arguments

overloaded methods of a class is a reflection of polymorphism

defined area of a circle, square, rectangular, trapezoidal area
2 and the sum of the number of //
public static void GetSum (a int, int B) {
System.out.println ( "a int, int B");
System.out.println (a + B);
}
public static GetSum void (int A, Double B) {
System.out.println ( "int A, B Double");
System.out.println (A + B);
}

Guess you like

Origin www.cnblogs.com/DHY868168/p/11241629.html