2016-11-01 5 views
0

내가 4 번을 표시합니다 (6) 두 번 표시하려면 난 다음 재귀를 사용하여이 6666 같은 서로 에 예를 두 번 지정된 시간이 주어진 숫자를 표시하려면이 질문이 코드가 있지만 그것은 스택 오버플로 누군가가 제발 내가이 재귀 새로 도움이 될 수 있습니다.표시 행

public static int i = 6; 
public static int j = 2; 

/** 
* @param args the command line arguments 
*/ 
public static void main(String[] args) throws IOException { 

System.out.print(addToTarget(i, j)); 


} 
public static int addToTarget(int n, int x){ 
int index = 0; 
if (index !=j*2){ 
    System.out.print(i); 
    index+=1; 
    return addToTarget(i,index); 
} 
return i; 

} 

답변

0

왜 이렇게 재귀가 필요합니까? 질문보기 1235179. 어떤 는

public static int addToTarget(int n, int x){ 
return new String(new char[x]).replace("\0", String.valueOf(n)); 
} 

그리고 정적 변수 및 매개 변수 사이에 어떤 엉망 당신이 가지고있는 것처럼 뭔가를 제안합니다!

+0

예. 지저분한 축하합니다 ... 도와 주셔서 너무 감사드립니다. – yousef