231211 JAVA -Arrays01 복습

2023. 12. 11. 18:392023.11.21-2024.05.31

package dec11;

 

import java.util.Arrays;

 

public class Array {

 

public static void main(String[] args) {

int arr1[]=new int[5];

 

System.out.println(Arrays.toString(arr1));

System.out.println(arr1[0]);

 

System.out.println("==============================");

 

double Dd[]=new double[3];

System.out.println(Dd[2]);

 

System.out.println("길이==============================");

System.out.println(Dd.length);

System.out.println(Dd[Dd.length-1]);

System.out.println(Dd[2]);

 

System.out.println("값대입==============================");

Dd[0]=123;

Dd[1]=200;

Dd[2]=300;

 

System.out.println(Dd.length);

System.out.println(Dd[Dd.length-1]);

System.out.println(Dd[2]);

 

System.out.println("=============================");

for (int i = 0; i < Dd.length; i++) {

Dd[i]=i+100;

}

for (int i = 0; i < Dd.length; i++) {

System.out.println(Dd[i]);

}

System.out.println("=======1부터 끝까지 지정 [1,2,3,4,5]======");

int arr11[]=new int[5];

for (int i = 0; i < arr11.length; i++) {

arr11[i]=i+1;

}

for (int i = 0; i < arr11.length; i++) {

System.out.println(arr11[i]);

}

 

System.out.println("==2=====1부터 끝까지 지정 [1,2,3,4,5]==2====");

for (int i = 0; i < arr11.length; i++) {

arr11[i] = i+1;

System.out.println(arr11[i]);

 

}

 

System.out.println("=foreach=====================");

for (int i : arr11) {

System.out.println(i);

}

 

System.out.println("=Arrays[1,2,3,4,5]=====================");

int arr2[]=new int[5];

for (int i = 0; i < arr2.length; i++) {

arr2[i]=i+1;

}

System.out.println(Arrays.toString(arr2));

 

double Dd2[]=new double[5];

for (int i = 0; i < Dd2.length; i++) {

Dd2[i]=i+100;

}

System.out.println(Arrays.toString(Dd2));

 

for (int i = 0; i < Dd2.length; i++) {

Dd2[i]=i+2;

}for (int i = 0; i < Dd2.length; i++) {

}

System.out.println(Arrays.toString(Dd2));

}

 

}

 

 

[0, 0, 0, 0, 0]

0

==============================

0.0

길이==============================

3

0.0

0.0

값대입==============================

3

300.0

300.0

=============================

100.0

101.0

102.0

=======1부터 끝까지 지정 [1,2,3,4,5]======

1

2

3

4

5

==2=====1부터 끝까지 지정 [1,2,3,4,5]==2====

1

2

3

4

5

=foreach=====================

1

2

3

4

5

=Arrays[1,2,3,4,5]=====================

[1, 2, 3, 4, 5]

[100.0, 101.0, 102.0, 103.0, 104.0]

[2.0, 3.0, 4.0, 5.0, 6.0]

'2023.11.21-2024.05.31' 카테고리의 다른 글

231212 JAVA -Test01 업앤다운 UP&Down 숫자맞추기 게임  (0) 2023.12.12
231211 JAVA -Arrays02 복습  (1) 2023.12.11
1211JAVA -DynamicArray03  (0) 2023.12.11
1211JAVA -DynamicArray02  (0) 2023.12.11
1211JAVA -DynamicArray01  (0) 2023.12.11