Operator Process Control

Source: Internet
Author: User

One, operator

1, arithmetic

+ - * /
%--Take surplus

++ --
+=  -=

Addition: +
Generally used for arithmetic between numbers
In addition: for concatenation of strings
Any type of data and string addition, the result is a string


Division:
Note the type of the result
Java.lang.ArithmeticException:/By zero


+ +--:
Position of the compound operator

If no other operators are involved,
Before and after, the effect is the same

2, Comparison operators
As long as there are comparison operators involved, the result is a Boolean type
< > <= >=
== !=

==:
Generally used for basic types to compare equality
Not suitable for comparison equality of object types: Using the Equals () method

3, logical operators
With or non: concatenate multiple Boolean values or Boolean expressions
Bitwise operations: Using 2 binary number operations
&--With
| -OR
Case
1, both sides are numbers.
2, both sides are of type Boolean

With: The same 1 is 1, the rest is 0
Or: The same 0 is 0, the rest is 1
1:0000 0001
2:0000 0010
&:0000 0000---0
|: 0000 0011---3
Logical operations: Only Boolean or Boolean expressions on both sides
&&--With
| |--or

When working with, or against, a Boolean value:
With: The truth is true, the rest are false
Or: the same false as false, the rest are true

Dual-and, or: short-circuit operations
Expression 1&& Expression 2
Expression 2 does not perform an operation if expression 1 returns false
If expression 1 returns True, an expression of 2 is executed
Expression 2 Returns True, Overall returns True, anyway, returns false
Expression 1| | Expression 2
Expression 2 does not perform an operation if expression 1 returns True
If expression 1 returns false, an expression of 2 is executed
Expression 2 Returns True, Overall returns True, anyway, returns false

4, XOR
^: Same as 0, different 1
1:0000 0001
2:0000 0010
^:0000 0011---3
5, shift
<< left shift number *2^ digits
>> right Shift number -2^ digits
3:0000 0011
<<2
0000 1100--12
>>1
0000 0001--1

Second, Process Control

1, conditional branching statement
Single BRANCH statement
If Else

if (condition)
Condition: Boolean value or Boolean expression

1.if statements can be used alone
if (conditional) statement

2.if Else pairing using
if (conditional) statement 1
Else Statement 2
The condition returns TRUE, executing statement 1,
Conversely, execute statement 2

Attention:
1, once if else is paired, the statements in if and else will only execute one of the
2,else statements cannot be used alone and must be paired with the IF statement
Else is always paired with his nearest if
3, whether the if or else can affect the statement only one
If you want to govern more than one statement, you must use {} to enclose it.
In the future, no matter how many statements, the habit will be added {}

3.if else if ....

Multi-branch statement
Switch (condition) {
Case value: statement;
.....;
Default: Statement
}
condition: Only byte, short, int, char, enum
Case: It's just a portal, and then the code executes in turn.
Control--Interrupt
Break --Jump out of a block of code that's closest to him

Trinocular operation
Simplifying the assignment operation of if Else
Variable = condition? value 1: Value 2;

2, loop
1.for
For (initialize loop condition; cycle critical point; ladder) {
Loop body
}

Typically used to know the number of cycles
For example, for arrays, traversal of collections, etc.

for (;;)---dead loop

Control:
Break --jump out of his nearest loop body.
continue;--end the current loop and start the next one directly

2.while
while (boolean/boolean expression) {
Loop body
}
First judge the condition, satisfy, execute the loop body
Generally used for situations where the number of cycles is not known
For example: file reading, result set traversal, etc.

Control program Function Menu

Add:
Package structure: The API in the JDK also has a package
Common packages:
Java.lang--Basic Package
Using the API under this package does not require a guided package operation (direct use)
In addition, the use of APIs in other packages must be guided by the package
Guide Package:
Import package name. class name;
Import Java.util.Scanner;
The package statement, you can have more than one
3.do while
do{
Loop body
}while (boolean value/boolean expression)

Execute the Loop body first and then judge the condition
ensure that the loop body is executed at least once

Operator 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.