aiLabel:

How to Get Array Length and Traversal Array in Java One dimensional Array

Butterflies fly
Favorable reply

In Java, an array is a data storage structure, a collection of data of the same type, which is used to store multiple data of the same type, and is also the basis for the implementation of the algorithm. Here's how to obtain the length of the array and traverse the array in Java one-dimensional array

Operation method

Open our Eclipse, create a new project, and create a new class in the project src directory.

To better manipulate arrays, Java provides the length attribute for arrays to obtain the array length. The syntax format is as follows.

Create the integer type variable array, initialize the assignment to {1, 2, 3, 4, 5}, create the integer type variable len, and use the variable array to obtain the array length of the variable len.

We use subscripts to reference array elements and obtain array length, and we can use circular statements to access all elements of the array.

Accessing array elements from front to back is an array traversal and iteration.

On the Java SE 5.0 platform, the enhanced for loop syntax, called for each loop, is added, which is more suitable for traversing arrays.

Create an integer type array, initialize the assignment, use the for each loop, and use the variable aa to access the value of each element in the array.

hot tip

Please point out any mistakes in this article

Butterflies fly 2024-05-26 02:31:53
The above contents quoted, excerpted or reproduced on this website are only for the exchange or reference of website visitors. The views or information in the text have nothing to do with Aiwen, and any matters and legal liabilities related to it have nothing to do with Aiwen.

Latest answers Change

one

Q: How do the letters represent the compass

Answer:
A: On the compass, E represents east, W represents west, S represents south, and N represents north. The compass, called Sinan in ancient times, is mainly composed of a magnetic needle mounted on a shaft. The magnetic needle can rotate freely and remain in the tangent direction of the magnetic meridian under the effect of the natural geomagnetic field. The north pole of the magnetic needle points to the geographical south pole, which can be used to identify directions. It is often used in navigation, geodesy, travel and military affairs. The compass is also one of the four great inventions in ancient China. It is the result of the understanding of the magnetism of magnets by the working people in ancient China in their long-term practice. It has played an invaluable role in the development of human science, technology and civilization.

Related recommendations

What does it mean that Apple's mobile phone installation software is gray

Apple mobile phone installation software is gray, which means that the software verification is not completed. Unlock the iPhone to the main screen, find [Settings] and open it. Jump to the option list of [Settings], and click [General] to proceed to the next step. Enter [
Details>
Question time: February 22, 2020

What is the zodiac sign that everyone loves

The beauty "Everyone Loves" refers to the Chinese zodiac rabbit. People who belong to the rabbit are optimistic, happy, unwilling to live a constrained life, and move forward in pursuit of ideals. The rabbit is one of the twelve Chinese zodiac signs. It runs four and twelve places dominate the "mao", so the "mao" time of the twelve hours of the day - from five to seven in the morning
Details>
Question time: November 5, 2019

How to calculate the interest of auto loan

The interest on auto loans is determined according to the amount of the loan, the term of the loan and the policy provisions of the lending bank. Generally, the interest rate of auto loans is obtained by floating on the benchmark loan interest rate stipulated by the state. The following is the formula for calculating the interest: interest=loan principal × loan interest
Details>
Question time: October 21, 2019

Is Yichun in Jiangxi developed

Yichun, Jiangxi Province is a medium to upper city, not particularly developed, but its economic level is also very good. This place has a large area and many people, convenient transportation, and a very good development prospect. So many people like to work and live here. Yichun, Jiangxi
Details>
Question time: January 11, 2020

What does the old disco mean

Disco for the Elderly means disco in the 1960s, also known as Diqu. Disco marks the beginning of early popular music based on dance music. Disco emphasizes beat, even singers and songs. It originated in France in the early 1960s. The word "Disco" is "Dis
Details>
Question time: October 15, 2020

How to grow coriander seeds

Gently crack the coriander seeds and soak them in 40 ℃ warm water for 6 hours. Pour the prepared soil into the container and pour it into water for standby. Sprinkle the seeds in the soil, cover a layer of thin soil about 1cm and water it in the morning and evening, and young seedlings will grow in about a month. The best kind of coriander seed
Details>
Question time: July 14, 2020

How to play the 24 hole harmonica

Use the harmonica to play Little Star in C major: 1155665-4433221-5544332-55443322-1155665-4433221, starting from the ninth hole of the left bass. Harmonica, (English Harmonic
Details>
Question time: November 23, 2019

What does it mean to be inaccessible

No one can catch up with others. It is often used as a compliment to describe being outstanding in some aspect. It is an idiom in Chinese. Idioms are a part of stereotyped phrases or short sentences in the vocabulary of Chinese characters. Idioms are a major feature of Chinese culture, with a fixed structural form and solid
Details>
Question time: August 16, 2020

What compound does na_2so_4 belong to

Na_2so_4 belongs to ionic compounds. Na2so4 is the chemical formula of sodium sulfate, which is colorless, transparent, large crystal or small granular crystal with hygroscopicity. It is mainly used for making glass, enamel, paper pulp, refrigeration mixture, etc. Compounds are composed of more than two
Details>
Question time: June 16, 2020

What are the peripheral cards for

A through card is an overdraft card, which is a kind of credit card. It does not need to deposit money in the card, but can also use the card to consume or withdraw money. After consumption or withdrawal, the money can be returned to the bank. The credit card can be used for consumption, ATM deposit and withdrawal, etc. The biggest advantage is that it can penetrate
Details>
Question time: November 12, 2020

What does pomegranate skirt mean

Pomegranate skirt is a fashion favored by young women in the Tang Dynasty. This kind of skirt is as red as pomegranate, and does not dye other colors. It often makes the woman wearing it beautiful and moving. Wan Chu of the Tang Dynasty said in "Five Days Watching a Prostitute": "Mei Dai wins the color of Xuancao, and Red Skirt is jealous of pomegranate flowers."
Details>
Question time: April 9, 2019

What is the viscosity coefficient of castor oil

The viscosity coefficient of castor oil, also known as internal friction coefficient or viscosity, is an important physical quantity to describe the internal friction properties of liquids. The viscosity of castor oil is much higher than that of general oils, 680CPS at 25 ° C, viscosity index 84, and friction coefficient 0.1
Details>
Question time: February 22, 2020

What is the temperature under the ovulation armpit

The temperature under the ovulation armpit is between 36 and 37.4 degrees. It is also normal that the temperature after ovulation is generally 0.3 to 0.5 degrees. Usually, you can check whether you are ovulating by monitoring your body temperature and using ovulation test paper. During ovulation, your body temperature will be higher than normal
Details>
Question time: January 28, 2020

How can hamsters not stink

You can choose litter type bedding materials, which have strong odor concealment ability and strong urine absorption ability. If you need to shovel off the pulled things, they will not smell so bad. For example, bentonite cat litter is slightly dusty. You can also spray some deodorant on the mat. Hamsters are
Details>
Question time: July 14, 2020