Java Fundamentals-Flow control statements and operators

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

Operator

Arithmetic operators

+ +--after the first operation to take the value, after the first value after the operation

Relational operators

= = = can also be a reference type
Bitwise operators

logical operators

Assignment operators

The conditional operator (?:)
Boolean expression? Expression 1: Expression 2
A Boolean expression with a value of true returns the value of expression 1 otherwise returns the value of expression 2
instanceof operator
This operator is used to manipulate an object instance to check whether the object is a specific type (class type or interface type).
(Object reference variable) instanceof (class/interface type)
Operation Priority

Process Control Statements

If statement
if else multiple if nested if
switch statement
switch (expression) {
Case value 1: code block 1
break;
Case Value 2: code block 2
break;
Default:
Defaults
}
Note:
The value of a switch parenthesis expression must be an integer or a literal after a character case can be a constant or a
constant expression case block can be merged with the default block can omit
3) while (Judging condition) {} perform the
4) do {
loop operation
} while (judging condition) after first judging;
Note: Execute first, then judge, do while guarantee statement executes at least once
5) for (loop initialization; loop condition; Change of cyclic variable) {} Three expressions can be omitted but cannot be omitted
The break keyword
Break is mainly used in loop statements or Switch statement to jump out of the entire statement block.
break jumps out of the innermost loop, and continues execution of the statement below the loop
The Continue keyword
Continue applies to any loop control structure. The function is to let the program jump immediately to the next iteration of the loop.
in the For Loop, the continue statement causes the program to jump immediately to the UPDATE statement.
in a while or Do...while loop, the program immediately jumps to the judgment statement of the Boolean expression. The
Java enhanced for Loop
Java5 introduces an enhanced for loop that is primarily used for arrays. The
Java enhanced for loop syntax is formatted as follows:
for (declaration statement: expression)
{
//code sentence
}
declaration statement: Declares a new local variable, and the type of the variable must match the type of the array element. Its scope is scoped to the Loop statement block, whose value is equal to the value of the array element at this time.
Expression: The expression is the name of the array to access, or is the method that returns the value to the group.
Example:

public class Test {public static void main(String args[]){int [] numbers = {10, 20, 30, 40, 50};for(int x : numbers ){System.out.print( x );System.out.print(",");}System.out.print("\n");String [] names ={"James", "Larry", "Tom", "Lacy"};for( String name : names ) {System.out.print( name );System.out.print(",");}}}

Java Fundamentals-Flow control statements and operators

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.