Java Basics (ii)-Statements, arrays

Source: Internet
Author: User

First, the statement

1.1. Conditional Statement 1.1.1.if statement

Syntax format:
if (expression) {  several statements  }
1.1.2. Branch statements (switch statements)

1.2. Circular statement 1.2.1for Loop statement

Analyzing result=1! in memory +2! ... +10! The algorithm

1.2.2while Cycle and Do~while cycle

1.2.3break and Continue

Two, array 2.1. Declaration format:

One-dimensional arrays:

Array name of the array element type [];

The array's element type [] array name;

Two-dimensional arrays:

Array of element type array name [];

The array's element type [] array name;

For example:

float boy[];

Char cat[][];

Declare multiple arrays at once:

int [] A, B;

Equivalent to

int a[],b[];

Special attention:

int [] a,b[];

Equivalent to

int a[],b[][];

2.2. Assigning element formats

Array name = new array element type [number of array elements];

For example:

boy= new float [4];

2.3. Use of arrays

If the number of array elements is n, the index of the array is from 0 to n-1

Use of 2.4.length

Array name. length

For a one-dimensional array, it represents the number of elements

For a two-dimensional array, it represents the number of one-dimensional arrays

2.4. Initialization of arrays

Once the array is created, the system defaults to a default value for each element

You can also assign an initial value to each element when declaring an array

Java Basics (ii)-Statements, arrays

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.