728x90
▶2차원 배열 선언 https://keichee.tistory.com/423
public static void main(String[] args){
int[][] array; //2차원 배열의 선언
array = new int[1][5]; //2차원 배열의 초기화
}
▶1차원
public static void main(String[] args){
int[] intArr1;
intArr1 = new int[3];
}
▶메소드에 다차원 배열 전달 https://www.delftstack.com/ko/howto/java/pass-array-to-method-in-java/
public class Main
{
public static void sum(int[][] arr)
{
int sum = 0;
for(int i = 0; i < arr.length; i++)
{
for(int j = 0; j < arr[0].length; j++)
{
sum = sum + arr[i][j];
}
}
System.out.print("Sum of all elements is: " + sum);
}
public static void main(String[] args)
{
int[][] arr = {
{1, 2, 3, 4, 5},
{2, 4, 6, 8, 10},
{1, 3, 5, 7, 9}
};
sum(arr);
}
}
▶스택 https://gmlwjd9405.github.io/2018/08/03/data-structure-stack.html
선언 및 초기화
Stack<Integer> stack = new Stack<>();
java 라이브러리 스택(Stack) 관련 메서드
push(E item)
해당 item을 Stack의 top에 삽입
Vector의 addElement(item)과 동일
pop()
Stack의 top에 있는 item을 삭제하고 해당 item을 반환
peek()
Stack의 top에 있는 item을 삭제하지않고 해당 item을 반환
empty()
Stack이 비어있으면 true를 반환 그렇지않으면 false를 반환
search(Object o)
해당 Object의 위치를 반환
▶Junit테스트 세팅
▶Junit사용방법
728x90
'코테 > Programmers' 카테고리의 다른 글
체육복) Array 활용 (0) | 2022.08.29 |
---|---|
없는 숫자 더하기) System.arraycopy 배열복사 (0) | 2022.08.24 |
키패드 누르기) (0) | 2022.08.21 |
최소직사각형) Math클래스 메소드 (0) | 2022.08.19 |
최소직사각형) 2차원 배열 (0) | 2022.08.19 |