728x90
반응형
SMALL
  • 동일한 특성을 갖는 변수의 모음
    • 0부터 시작(cf R, fortran, pascal에서는 1로 시작)
ex) 
student1
student2
student3
.......
student1000          //이렇게 하나하나 만드는 것이 아니라
 student[1000]  > student[38] = 'diogfoieh'
                      //대 괄호 안에 숫자를 넣어주면 알아서 만듬 //크기 x 떨어진 거리만큼 있겠다는 의미

 lista = [1, 3, 'jwlee', String str]

파이썬은 다 받아주지만, 자바와 C는 안됨! //참고사항
장점은 꺼낼때 어떤 타입인지 알 수 있다.
package Day03;

public class ArrayTest {	

	public static void main(String[] args) {
	//  TODO Auto-generated method stub
	System.out.println("**** Array Test ****");

	String[] student1 = new String[5];
	String[] student2 = {"A", "B", "C", "James", "E"};
	int[] student_score = new int[5]; //고정된 숫자는 중간에 바꾸지 못한다.

	for(int i=0; i<5; i++) {
		System.out.println(student2[i]);
	}

	System.out.println(student2.length);

	for(int i=0;i<student2.length;i++) {
		System.out.println(student2[i]);

	} //자주 나오는 문장

	for(String str : student2) {
		System.out.println(str);
	} //자주 나오지는 않지만 까먹을 수 있는 문장!

	}

}
package Day03;

public class ArrayTest {

	public static void main(String[] args) {
	//  TODO Auto-generated method stub
	System.out.println("**** Array Test ****");

	String[] student1 = new String[5];
	String[] student2 = {"A", "B", "C", "James", "E"};
	int[] student_score = new int[5]; //고정된 숫자는 중간에 바꾸지 못한다.

	for(int i=0; i<5; i++) {
		System.out.println(student2[i]);
	}

	System.out.println(student2.length);

	for(int i=0;i<student2.length;i++) {
		System.out.println(student2[i]);

	}

	for(String str : student2) {
		System.out.println(str);
	}

	// 2-d array
	int[][] m_array = new int[3][4];
	int[][] m_array2 = {{1,2,3},{4,5,6}};
	int[][] m_array3 = {{1,2,3},{4,5,6}};

	// 5를 선택하는 방법
	System.out.println(m_array2[1][1]);

	System.out.println(m_array2[0]);
	m_array2[0][2] = 100;
	System.out.println(m_array2[0]);

	System.out.println(m_array2);
	System.out.println(m_array3);

	System.out.println(m_array2 == m_array3);

	//System.out.println(m_array2 == m_array3);
	//2와 3이 같은 값을 가지고 있더라도 완전히 같지 않다. 동명이인이랑 같은 의미

	//System.out.println(m_array[0][0] == m_array3[0][0]);
	//단 위에 문장은 같음!!

	}

}

3차원 이상 배열 [][][]

정신적으로 만들지 않음...

2차원까지 하는 이유는 여기까지가 효율적이기 때문

int[][][][][] m_array = new int[3][4][5][6][7];

 

package Day03;

public class ArrayTest {

	public static void main(String[] args) {
	//  TODO Auto-generated method stub
	System.out.println("**** Array Test ****");

	String[] student1 = new String[5];
	String[] student2 = {"A", "B", "C", "James", "E"};
	int[] student_score = new int[5]; //고정된 숫자는 중간에 바꾸지 못한다.

	for(int i=0; i<5; i++) {
		System.out.println(student2[i]);
	}

	System.out.println(student2.length);

	for(int i=0;i<student2.length;i++) {
		System.out.println(student2[i]);

	}

	for(String str : student2) {
		System.out.println(str);
	}

	// 2-d array
	int[][] m_array = new int[3][4];
	int[][] m_array2 = {{1,2,3},{4,5,6}};
	int[][] m_array3 = {{1,2,3},{4,5,6}};

	// 5를 선택하는 방법
	System.out.println(m_array2[1][1]);

	System.out.println(m_array2[0]);
	m_array2[0][2] = 100;
	System.out.println(m_array2[0]);

	System.out.println(m_array2);
	System.out.println(m_array3);

	System.out.println(m_array2 == m_array3);

	//System.out.println(m_array2 == m_array3);
	//2와 3이 같은 값을 가지고 있더라도 완전히 같지 않다. 동명이인이랑 같은 이미

	//System.out.println(m_array[0][0] == m_array3[0][0]);
	//단 위에 문장은 같음!!

	}

}
728x90
반응형
LIST

'개발 > JAVA' 카테고리의 다른 글

함수(function)  (0) 2023.01.09
Colors (추후 수정 필요 !)  (0) 2023.01.09
제어문(Control Statement)  (0) 2023.01.09
Random (임의의 수를 얻는 도구)  (0) 2023.01.09
User Input (사용자로부터 입력을 받는 기능)  (0) 2023.01.09

+ Recent posts