How java uses arrays
This article mainly shows you "java how to use arrays", the content is easy to understand, clear, hope to help you solve your doubts, the following let the editor lead you to study and learn "java how to use arrays" this article.
Use a simple array
(1) create a class named T04 and declare two variables array1 and array2 in the main () method
They are arrays of type int [].
(2) using curly braces {}, array1 is initialized to 8 primes: 2, 3, 5, 7, 11, 13, 17, 19.
(3) display the content of array1.
(4) assign the array2 variable to be equal to array1, and modify the even index element in array2 to equal the index value (for example, array [0] = 0, array [2] = 2). Print out the array1. * * think: what is the relationship between array1 and array2?
Extension: modify the title to realize the replication of array1 array by array2
Public class T04 {public static void main (String [] args) {int [] array1,array2; array1=new int [] {2, 3, 5, 7, 11, 13, 17, 19}; for (int ionomy 0 teri)
< array1.length;i++){ System.out.print(array1[i]+"\t"); } //赋值array1变量等于array2 //不能称作数组的复制 array2=array1; for(int i=0;i< array1.length;i++){ if(i%2==0){ array2[i]=i; } } System.out.println(); System.out.println("******************************************"); for(int i=0;i< array1.length;i++){ System.out.print(array1[i]+"\t"); } }}
(1) both array1 and array2 address values point to the unique array entity in the heap space.
(2)
For (int iTuno Bandi)
< array1.length;i++){ array2[i]=array1[i]; }
Method 2
Int iTunes 0; int jung0; for (iTuno Junior j = arr.length-1;i