본문 바로가기
코테/Programmers

크레인 인형뽑기) 배열, 스택, junit테스트

by Wanado 2022. 8. 23.
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테스트 세팅

https://velog.io/@ynjch97/JUnit5-Spring-Boot-Gradle-%ED%99%98%EA%B2%BD%EC%97%90%EC%84%9C-JUnit5-%EC%A0%81%EC%9A%A9-%ED%85%8C%EC%8A%A4%ED%8A%B8-%EC%8B%A4%ED%96%89%ED%95%98%EA%B8%B0

 

▶Junit사용방법

https://junghn.tistory.com/entry/Eclipse-%EC%9E%90%EB%B0%94-JUnit-%EC%82%AC%EC%9A%A9-%EB%B0%A9%EB%B2%95-%EB%8B%A8%EC%9C%84-%ED%85%8C%EC%8A%A4%ED%8A%B8-%EB%B0%A9%EB%B2%95

 

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