In java variables and control statements

Details First, variable
life cycle 1. variables:
a variable is created and allocated memory space begins to clear this variable is destroyed and the process they take up memory space.
2. classification variables
(1) member variables (instance variables)
have default values
Integer: 0 Float: 0.0 char: Type: '\ u0000' boolean: false reference type: null
(2) a local variable
in the method, code block statement
scope: only the code block used in the method.
Local variables will not default assignment, the assignment must first re-use.
Local variables can not be other than the method using the local variables.

Second, the control statements
1.if statements
if (Boolean expressions) code blocks {}
almost continuousl () {} {} the else
3.If () {} the else if () {} the else if () {} {} the else
4.switch statement
syntax: Switch (expr) {
                Case VALUE1:
                    codes;
                    BREAK;
                Case value2:
                    codes;
                    BREAK;
                ...
                default:
                    Code;
                    BREAK;
              }
expr supported data types:
the latter expression data type switch only supports byte, short, char, int four kinds of type integer, and enumerated types java.lang.String type.
Process explanation:
         1 to get the value of expr
         2, from top to bottom and the case of the comparative value
             if the same execution of the current case the following code (can be multi sentences, lines of code),
                 if not break, then the next case will match all the success (even if case and a different value expr), and then execute the code in the case. Then perform default
                 if there break, then the switch is finished, jump out.
         3, if the match fails case all
             execution code default
5. loop: for repeatedly circulating a piece of code
6.for cycle
 Syntax: for (initialization portion: Cycling conditions: Iterative portion) {
            loop body
          }
EG:. 1 and added to 100
                 int sum = 0;
                for (int I =. 1; I <= 100; I ++) {
                                     SUM = SUM + I;
                                   }

7.while cycle
 Syntax: while (loop condition) {
        loop body
    }

EG:
                  int = I. 1;
     int SUM = 0;
 the while (I <= 100) {
     SUM = SUM + I;
     I ++;
 }
8.do - the while loop
 syntax: do {
         loop
        } while (loop condition);

9.break and continue the difference between
break and continue are used to control loop structure, the role is to stop the cycle.
break: End of complete cycles
continue: out of this cycle, the next cycle into the
for (int I =. 1; I <=. 9; I ++) {
            IF (I ==. 5) {
                Continue;
            }
            System.out.println ( "Continue:" + I);
        }
        System.out.println ( "End");
// Results:
Continue:. 1
Continue: 2
Continue:. 3
Continue:. 4
Continue:. 6
Continue:. 7
Continue: . 8
Continue:. 9
end


replaced BREAK:
Continue:. 1
Continue: 2
Continue:. 3
Continue:. 4
end

Guess you like

Origin www.cnblogs.com/yxj808/p/11939347.html