3 Replies - 628 Views - Last Post: 07 April 2009 - 03:17 PM Rate Topic: -----

#1 seytorin  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 06-April 09

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.

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;
			}


Is This A Good Question/Topic? 0
  • +

Replies To: Having trouble drawing a box

#2 Fuzzyness  Icon User is offline

  • Comp Sci Student
  • member icon

Reputation: 669
  • View blog
  • Posts: 2,438
  • Joined: 06-March 09

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?
Was This Post Helpful? 1
  • +
  • -

#3 seytorin  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 06-April 09

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.
Was This Post Helpful? 0
  • +
  • -

#4 seytorin  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 06-April 09

Re: Having trouble drawing a box

Posted 07 April 2009 - 03:17 PM

Anyone else have any ideas?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1