User input: 4 (ignore the extra spaces inbetween each,, there should be no extra line inbetween) Result: XXXX
XXX
XX
X
X
XX
XXX
XXXX
I have created a method in which i think should do it but I am having a problem wiht it
This si the code I have so far
n is the input number z is a counter to try and go between making a backwards/ forwards triangle
public static String drawLine(int n, int z){
if(n!=0&& z<(n+1)){
for(int i=1;i<=n;i++)
System.out.print("X");
System.out.println();
z+=1;
drawLine(n-1,z);
return"";
}
else{
if( z==(2*n+1) ) return "";
z+=1;
String p = drawLine(n - 1,z);
p = p + "X";
System.out.println(p);
return p; }
}
the error message is that there is some infinit loop or an over flow, but I cannot find the error....please help!!

New Topic/Question
Reply


MultiQuote


|