Java methods, operators, and Process Control

Source: Internet
Author: User

1. Java method Methods (function functions), functions, actions
1) The method is the function: Y=f (x) =3x+6;
2) syntax of the method
(modifier words) (return value type) (Method Name) (parameter list) {
Method body
}
public static void Main (string[] args) {}
Such as:
public static int f (int x) {
int y = 3 * x + 6;
return y;
}
4) If there is a return value definition there must be a return statement, return and return value type
Compatible data
5) The parameters of the method and the variables inside the method are local variables,
These variables are scoped only inside the method!
6) Arguments: parameter variables that are actually passed when the method is called
Parameters: The parameter definition of a method, which is a temporary variable.

2. Java operators
1) Math operator +-*/%
The closure of a operation (the closeness of the complement operation):
1. Join operations of the same type (may require automatic type conversion)
2. Return the same type (may occur: up overflow and down overflow)
3.byte, short, char by int
such as: int a = 1 + ' a ';
B. Division of integers is divisible, divided by 2 equivalent to shift operation (moving decimal point)
The arithmetic of the literal in C.java is optimized by Javac and optimized to a fixed constant.
D.% calculates the remainder of division
1.0 The remainder of the other numbers is 0
2. n%3 is a periodic function, function value [0,3]
3. Negative remainder is negative (exams may appear, rarely used in work)

2) Self-increment (self-subtraction) operation + +--
1. Can increase the current variable self (decrease) 1
2 i++, after + +, first the value of I as the entire expression value, and then add I 1.
3 ++i, first + +, first increase the I 1, and then the value of I as the entire expression value.

(i++)%3 is equivalent to i%3

3) Logic and comparison operations
1. Logical operation with (and) && or (or) | | Non (otherwise)!
Non-short-circuit Logic Operations & | , less use, logic unreasonable, so-called short-circuit is once judged to be false, terminate run the following statement. Non-shorted, true or false, will run
2. Comparison operation, compare the value of the variable, is the "bit" Comparison value: > >= < <= = = =!
The value of the base type variable is the base value such as: I=1
The value of the reference type variable is the object address value. (Detailed explanation in the object-oriented phase)

int i = 1;
Long L = 1;
System.out.println (I==L); True
4) Conditional operator (3-tuple operator)
Syntax: boolean expression? Expression 1: Expression 2
When Boolean expression is true, expression 1 is used as the value of the entire expression.
Otherwise, expression 2 as the value of the entire expression
Such as:
Boolean isboy = true;
int level = Isboy? 2:3;//2

3. Branch Process Control
1) If ... else
Syntax: if (Boolean expression) {
Statement BLOCK:
}else{
Statement block
}
Nested: if (Boolean expression 1) {
//...
}else if (Boolean expression 2) {
//...
}else if (Boolean expression 3) {
//...
}else{
//...
}

if () {
if () {
if () {
//?
}
}
}


2) Switch ... case
Syntax: switch: switches, Case: Cases
Switch (integer expression) {
Case Integer constant 1:
Statement sequence
Break
Case Integer constant 2:
Statement sequence
Break
Default
Statement sequence
}
A. Switch condition: Can only be an integer (int byte char short) expression
Switch cannot handle long or other types
B. Case can only be an integer (int byte char short) constant and cannot be used
Variables and expressions. such as: ' Medium '
C. Break jumps to the end of the switch to continue execution, depending on whether the business logic uses
Often write break

4. Cycle control
1) While loop control
Grammar:
while (Boolean expression) {
Loop Body Statement Sequence
}

Java methods, operators, and Process Control

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.