0
'java collatz 7'명령을 실행하면이 collatz 코드가 생성되고, n이 1에 도달하면 프로그램이 종료되지 않고 대신 StackOverflowError까지 시퀀스가 반복됩니다. 누구가 여기에서 문제점이인지 지적 할 수 있 었는가? 들으자바 collatz 코드가 도달 할 때 멈추지 않는다
이 문제처럼 보인다public class collatz{
public static void collatz(int n){
System.out.println(n+" ");
if(n==1)
return;
if(n%2==0)
collatz(n/2);
collatz(n*3+1);
}
public static void main(String[] args){
collatz(Integer.parseInt(args[0]));
}
}
@D M Thank you! – rifle123