코테 에러(기본 실수 편)

buffet_psi·2023년 3월 26일

끄적끄적

목록 보기
5/7
class Solution {
    public int[] solution(int n) {
        int count = 0;
        for(int i=0; i<=n; i++){
            if(n%i==0){
                count++;
            }
        }
        int co =0;
        int[] answer = new int[count];
        for(int i=0; i<=n; i++){
            if(n%i==0){
                answer[co] = i;
                co++;
            }
        }
        return answer;
    }
}

Exception in thread "main" java.lang.ArithmeticException: / by zero
at Solution.solution(Unknown Source)
at SolutionTest.lambdamain$0(Unknown Source) at SolutionTestSolutionRunner.run(Unknown Source)
at SolutionTest.main(Unknown Source)
0으로 나누려고 할 때 발생하는 오류코드
코드에서 for문에 int i =0부터 시작하는데 나누력고 하니 오류가 날 수밖에 즉 int i =1로 바꿔줘야한다

profile
노력과효율!

0개의 댓글