5 Replies - 708 Views - Last Post: 16 April 2009 - 10:00 PM Rate Topic: -----

#1 Warchief08   User is offline

  • New D.I.C Head

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

Java Help

Posted 16 April 2009 - 12:25 PM

trying to draw a staircase with a constant to control the number of stairs displayed.
public class TryAgain
{
	public static final int SIZE = 2;
	
	public static void main(String [] args)
	{
		printTopFloor();
		
	}
	public static void printTopFloor()
	{
		for(int line = 0; line < SIZE; line++)
		{
			printSpaces(line);
			printHead(line/2+1);
			printBody(line/2+1);
			
			System.out.println();
		
		}
		
	}
	public static void printSpaces(int howMany)
	{
		for (int line = SIZE+1; line > howMany; line--)
		{
			System.out.print('a');
		}
	
	}
	public static void printHead(int howMany)
	{	
		int i,j,k;
		char head = 'o';
		 
			
			for(j=SIZE; j>howMany; j--)
			{
				System.out.print(head);
				System.out.print(" " +  " ");
			}
			for( j=7; j>=1; j--)
		   {
				System.out.print('*');
			}
			System.out.println();
	}
	public static void printBody(int howMany)
	{
		for (int j = SIZE; j>howMany; j--)
		{
			System.out.print("/|\\ *");
		}
	}	

	
}


Please Help! I have no idea what I am doing and the teacher isnt helping!!

Is This A Good Question/Topic? 0
  • +

Replies To: Java Help

#2 mostyfriedman   User is offline

  • The Algorithmi
  • member icon

Reputation: 729
  • View blog
  • Posts: 4,473
  • Joined: 24-October 08

Re: Java Help

Posted 16 April 2009 - 06:50 PM

i dont understand what kind of shape are you trying to display, can you post a sample output
Was This Post Helpful? 0
  • +
  • -

#3 pbl   User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8378
  • View blog
  • Posts: 31,956
  • Joined: 06-March 08

Re: Java Help

Posted 16 April 2009 - 06:55 PM

Please respect rule #5 of this forum: Give your topic a descriptive title, NOT "Help" or "Plz Help Me" or "I'm a noob"
Naming a topic "Java Help" in a forum devoted to help people in Java is kind of useless and won't attract specialists in the field in which you have a problem
Was This Post Helpful? 0
  • +
  • -

#4 DaneAU   User is offline

  • Great::Southern::Land
  • member icon

Reputation: 286
  • View blog
  • Posts: 1,620
  • Joined: 15-May 08

Re: Java Help

Posted 16 April 2009 - 08:10 PM

Are you trying to draw stairs similar to the following image however simply using some character ?

class Stairs
{	
	private static int RUN = 4;
	private static int RISE = 3;

	int walkDown()
	{
		int p_x = 0, steps = 0;

		while ( steps < 10 )
		{
			int counter = 0;
		
			for(int k = 0; k < p_x - 1; k++)
			{
				System.out.print(" ");
			}
			do
			{
				System.out.print("*");
				counter++;
				p_x++;
			
			} while ( counter < RUN  );
			
			if(steps > 0)
			System.out.print("*");


			System.out.print("\n");
			counter = 0;		
			do
			{

				for( int i = 0; i < p_x - 1 ; i++)
				{
					System.out.print(" ");
				}
				System.out.print("*\n");
				counter++;
				

			} while ( counter < RISE );

		steps++;
		}

		return 0;
	}

	public static void main(String[] args)
	{
		Stairs myStairs = new Stairs();
		System.exit( myStairs.walkDown() );
	}
}


The output looks similar to the image below

Attached image(s)

  • Attached Image

This post has been edited by bbq: 16 April 2009 - 08:38 PM

Was This Post Helpful? 0
  • +
  • -

#5 pbl   User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8378
  • View blog
  • Posts: 31,956
  • Joined: 06-March 08

Re: Java Help

Posted 16 April 2009 - 08:24 PM

View Postbbq, on 16 Apr, 2009 - 07:10 PM, said:

Are you trying to draw stairs similar to the following image however simply using some character ?

lol
impressive

View Postpbl, on 16 Apr, 2009 - 07:23 PM, said:

View Postbbq, on 16 Apr, 2009 - 07:10 PM, said:

Are you trying to draw stairs similar to the following image however simply using some character ?

lol
impressive

Actually wonder how you do that ?

*Edited: never mind just realize it is an attached image :-)

This post has been edited by pbl: 18 April 2009 - 02:28 PM

Was This Post Helpful? 0
  • +
  • -

#6 DaneAU   User is offline

  • Great::Southern::Land
  • member icon

Reputation: 286
  • View blog
  • Posts: 1,620
  • Joined: 15-May 08

Re: Java Help

Posted 16 April 2009 - 10:00 PM

lol pbl - i have no idea what you are going on about :S
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1