public class birdarray {public static void main (string args []) {string [] str = new string [] {"sparrow", "eagle", "white pigeon", "bleverbird", "peacock", "peacock" "," Parrot "," Daniel Crane "}; int index = 0; // Create an index variable system.out.println (" There are many birds in the park, the types include: "); While (index <str.length) { / / /Like the array system.out.println (str [index ++]); //
Output:
Run: There are many birds in the park. The types include: Sparrow Eagle White Pigeon Bird Bird Bird Peacock Parrot BUILD Successful (Total Time: 0 Seconds)
Summarize:
Create an index variable INDEX, which is used to specify the setting of the array. As the indexes increase, the While loop will gradually traverse each element and output to the console. Pay attention to ++ index, the difference from Index ++.
++ Index: The value of INDEX increases, and then uses the value of the incremental value.
Index ++: First use the value of index, and then increase the value of the variable.