(Transferred from new blogger Education Huang Yuxin teacher)
1, ternary operator (trinocular operator):
Syntax: x?y:z; (it's just an expression);
Expression: cannot have an equal sign present, other types can be defined; it has only two types (values and types);
Note: int b=x?y:z; (At this point the y,z must be consistent with the type of B) there is no strict requirement for X, as long as it is a Boolean type;
2. If condition:
The execution process of code is divided into three kinds: sequential structure, selection structure and cyclic structure;
Syntax: (four types)
if (Boolean) {< statement block >};
if (Boolean) {< statement block >}else {< statement block >};
if (Boolean) {< statement block >}else if (Boolean) {< statement block >}....else if (Boolean) {};
if (Boolean) {}else if () {}...else{}
Note: 1, 3 kinds of do not necessarily output, and 2, 41 have one to be output; if conditions are "single-minded"
3, Switch: (case statement) (mainly JDK1.7)
Grammar:
Switch (can put any type 1) {
Case Type 1:
< statement block >
Break
Case Type 1:
< statement block >
Break
.....
Default
< statement block >
}
If there is no break this keyword, it can penetrate, continue to execute the following statement until a break or the end of the statement is encountered;
Note: efficiency: ternary operator >switch () >if ();
4. While loop:
Grammar:
650) this.width=650; "Src=" http://note.youdao.com/yws/public/resource/719ed66494263eb983dad4d9b8549a6b/ Ec5fa8ff35ce4454b8ad8b81ccb6bb72/2be0f449e576488197cb656c8a9e27e4 "style=" Border:none;height:auto; "alt=" 2be0f449e576488197cb656c8a9e27e4 "/>
Note: When using while, you should pay attention to the control conditions of the loop, there is no statement after the dead loop;
5, do{< statement block >}while (expression);
Do.. while (): A statement is executed first, then judged; so anyway, it's going to be executed at least once;
While: the execution of the statement is judged before it is not necessarily executed;
Note: do.. while (); ";" This semicolon can not be less; suggestion: beginners do not use first;
6. For loop:
Grammar:
For (variable type variable name = initial value; number of cycles; step) {< statement block;}
Note: The step: is executed after the statement block is finished;
For,while cycle, can be used to each other;
When do I use for, and when to loop? (Personal advice)
A: For loop, the cyclic condition is more used, while loop, accumulate, judge the number of cycles;
7, Break,continue,return:
Break: Live in a switch or loop statement, indicating the end of the current loop;
Continue: Survive in the loop statement, indicating the end of the cycle, continue the next cycle;
Return: Live in a method with a return value, indicating the end of the entire method;
8. Static method:
Grammar:
Public +static +void/Type + method name (formal parameter/no parameter) {< statement block;}
Classification:
No return value: Must be modified with void;
Example:
public class a{
public static void F () {//cannot have return;}
public static void Main (string[] args) {
f ();//cannot assign value;
}
}
Has return value: Must have return type, return:
Example:
public class a{
public static int F () {
return int type;
}
public static void Main (string[] args) {
You can assign values:
int b=f ();//b=return returns the value;
}
}
This article is from the "Kun" blog, please be sure to keep this source http://linyingkun.blog.51cto.com/2393912/1570998
Android Training Lesson Two notes