public static String drawBox(int s){
String result="";
for (int i =1; i<s; i++)result +="* ";
for (int i = 1; i<s;i++){
for (int j=0; j<=s;j++){
if(j==0 || j==s-1)result +="*";
else for(int h=2;h<j;h++)result += " ";
}
result +="\n";
}
for (int i =0; i<s; i++)result +="* ";
return result;
}
Having trouble drawing a box
Page 1 of 13 Replies - 527 Views - Last Post: 07 April 2009 - 03:17 PM
#1
Having trouble drawing a box
Posted 06 April 2009 - 09:37 PM
Hey I've been having trouble getting a box drawn in java. I need to draw one when either the number 9 or 17 is entered. It almost works with 9 but there is a stray star to the right of it. 17 is worse because the right side of the box is too many spaces away from the rest of the box. Here is the method that I have right now. I would greatly appreciate any suggestions. Thanks.
Replies To: Having trouble drawing a box
#2
Re: Having trouble drawing a box
Posted 06 April 2009 - 10:11 PM
for (int j=0; j<=s;j++){
Im pretty sure that should be j<s; yeah?
Im pretty sure that should be j<s; yeah?
#3
Re: Having trouble drawing a box
Posted 06 April 2009 - 10:16 PM
I actually tried that but it didn't change my results. Thanks for the suggestion though.
#4
Re: Having trouble drawing a box
Posted 07 April 2009 - 03:17 PM
Anyone else have any ideas?
Page 1 of 1
|
|

New Topic/Question
Reply




MultiQuote



|