Basic introduction and examples of array operators and control processes

Source: Internet
Author: User
Tags arithmetic operators bitwise operators logical operators

Summarize

One, array

1. Concept

2. Role and examples

Second, operator

1. Classification

1) Arithmetic operators

2) Bitwise operators

3) Comparison operators

4) Logical operators

Third, Process Control

1. Sequential Process

1) if

2) If Else

3) If Else if

2. Branch Process

1) switch

3. Circulation Process

1) for

2) while

3) Do While

One, array

1, Concept: is the same data type collection

2, Function: The array itself is a reference type, that is, the object,

Created with new, you can store basic data types, or you can store reference type data, such as:

String a "" = new A "" {"Husky", "Wood dog", "Pine Lion"}

int a "" = new int "" {1,1,2,3,4,5}

Second, operator

1. Classification:

V arithmetic operator

1) single-Mesh:+ (Take positive)-(minus) + + (self-increment 1)--(auto minus 1)

int a=1;

Int b;

B=a++/++a//a++ is first used value, then self-increment, ++a is the first self-increment, and then use the value

Running result: b=0//The same thing--the same reason

2) Binocular:+-*/% (residual) (+ can also connect string, not actual output)

System.out.println ("Hello" + "job");

running result: Hello Homework

3) three mesh:a>b?true:false Comment: Determine the size of a and B, its logical result is a Boolean type, if the fruit is ture, then the output ture value, if A>b is not true, then output false value.

The colon can be either an expression or a value, or it can be an object

Int a = 3;

Int B = 4;

Int C;

c = a>b?a++:b++;

System.out.println ("c=" +c);

System.out.println ("a=" +a);

Operation result is c=4

A=3

V-bit operators:

calculation principle: first conversion into binary and then operation

with (&), non-(~), or (|), XOR (^)

shift operators:<<, >> (signed right Shift), >>> (unsigned Right shift)

int a=8, C; The binary of a is 0000 1000

c=a>>2; Move right two bits is 0000 0010 (decimal is 2)

the output is c=2

V comparison operator

1) = =, <,>,<=,>=,!=

2) = = vs. = Compare the base data type is the comparison value, compare the reference type is the memory virtual address of the comparison

3) In addition to = = =, you can only compare the basic data type, which is the comparison value.

The return value of the comparison operator is Boolean,true or False

V Logical operators

Expressions for connecting two Boolean types

&& (double and), | | (dual or), & (with), | (or), ^ (XOR),! (non-operational)

For example:

Int iyear;

Can be divisible by 4 and not by 100, or divisible by 400.

if (iyear% 4 = = 0 && iyear% 100! = 0| | Iyear%400==0) {return true;
} else {
System.out.println ("This is not a leap year, please re-enter");
}

Note Summary:

1) && and & operation results are the same, for & regardless of the left side of the value, the right to participate in the operation, for &&, as long as the left is false to the right is no longer the operation, directly return False

2) | | The result of the operation is the same as that for | The right side, regardless of the value on the left, participates in the operation; for | | , as long as the left is true, the right side is no longer calculated and returns true directly.

3) && | | Can be understood as a physical short circuit, the actual multi-use && and | |

Third, Process Control

    1. Sequential process

L IF

For example

if (a>b) {//Judging condition if a>b

System.out.println ("This Is Love")//Conditions Meet output "This is Love"

}

L If...else ...

For example

if (a>b) {//Judging condition if a>b

System.out.println ("This Is Love")//Conditions Meet output "This is Love"

}else{//Not satisfying the judging condition

System.out.println ("This is annoying")//output "This is annoying"

}

L If...else If ...

For example

if (a>b) {//Judging condition if a>b

System.out.println ("This Is Love")//Conditions Meet output "This is Love"

}else if (a<b) {//Condition a>b not satisfied at the time of the judgment condition A<b

System.out.println ("This is annoying")//output "This is annoying"

}

    1. Branching process

-switch

Char a= ' 1 '; Defines a char type variable a

Switch (a) {

Case ' 1 ':

System. out. println ("Hot dead");

break;

Case ' 2 ':

System. out. println ("The weather is really hot");

break;

Case ' 3 ':

System. out. println ("Xi ' an is a big oven");

break;

Case ' 1 ':

System. out. println ("Life is in Motion");

break;

Default

System. out. println ("Ordinary life is very strong");

}

Where break is interrupted, when a condition-level run to the event is met, execution begins, execution of the statement jumps out of all loops and outputs

Switch (description)

2 The value of the expression can only accept int, Byte, char, short, enum, JDK1.6 string can also, do not accept other types of values, do not allow duplicate case value

2 Switch Once you hit the first case match, the program jumps to the tab location.

2 start all program code after execution, regardless of whether the following case conditions match, until the break statement is encountered

    1. Cycle flow

L for

Grammatical structure

for (initialize expression; loop condition expression; post-loop action expression) {

EXECUTE statement block

}

For example:

Define a shape A, give him a memory space, and assign 0 to the A,a cycle range is less than 0, the loop is self-increasing

for (int a=0,a<10,a++) {

The value of output a after the loop structure is completed

System.out.println ("a=" +a)

}

L while

Grammatical Structure

while (conditional expression)

{

EXECUTE statement block

}

For example:

Open a memory space to x, define X, and assign the initial value to X

int x=10;

while (x<15) {//Loop expression is when x is less than 15 o'clock, enter the loop

System.out.println ("x=" +x); The output from the X value is from 10 to 14.

x + +; Cycle mode

}

L Do...while

Grammatical structure

do{

Executes the statement block;

} while (conditional expression);

For example:

int y=3; open a memory space for y, define Y, and assign the initial value to Y

Do {

System.  out. println ("y=" +y); EXECUTE statement block

y++;

} while (y<5); Judging condition start cycle

Break, continue: Interrupt statement

labels can be used in multiple loops to specify the specific loop of the interrupt , which breaks the entire loop, continue interrupts the current loop, and proceeds to the next loop. Both are used only in loop statements.

for (int i=1;i<11;i++) {

if (i==7) {

continue;

}

System. out. Print (i+ "");

}

the output is:1,2,3,4,5,6,8,9,10

Jump out of the loop point to continue the next loop

Basic introduction and examples of array operators and control processes

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.