2 Replies - 11298 Views - Last Post: 06 November 2007 - 05:25 PM Rate Topic: -----

#1 sgmikewoody  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 15
  • Joined: 30-September 07

Oh Christmas tree oh Christmas tree

Post icon  Posted 06 November 2007 - 11:47 AM

About 2 hours into this one, not too much invested, but I figured someone could point me in the right direction.

	public class ChristmasTree
	{
		public static void main (String[] args)
		{
			int numberOfLines1;
			int numberOfLines2;
			int numberOfLines3;
			int counter;
			int numberOfBlanks;
			
			numberOfLines1 = 15;
			numberOfLines2 = numberOfLines1/3 + numberOfLines1/3;
			numberOfLines3 = numberOfLines1/3;
			
			numberOfBlanks = 30;
			
			for (counter = 1; counter <= numberOfLines3;
									counter++)
			{
				printTree(numberOfBlanks, counter);
				numberOfBlanks--;
			}
			
			for (counter = 5; counter <= numberOfLines2;
									counter++)
			{
				printTree(numberOfBlanks, counter);
				numberOfBlanks--;
			}

			for (counter = 10; counter <= numberOfLines1;
									counter++)
									
			{
				printTree(numberOfBlanks, counter);
				numberOfBlanks--;
			}
			
		}
		
		public static void printTree(int blanks, int starsInLine)
		{
		int count;
		int counter =1;

		for (count = 1; count <=blanks; count++)
				System.out.print(" ");
		for (count = 1; count <=starsInLine; count++)
				System.out.print(" *");
			System.out.println();
			counter++;
			
		
		}
	}


I know, I suck. I'm probably approaching this the wrong way, I'm sure. I'll continue to fiddle with it, but if anyone has any recommendations, I'm all ears.

The output looks like this btw

*
* *
* * *
* * * *
* * * * *
* * * * *
* * * * * *
* * * * * * *
* * * * * * * *
* * * * * * * * *
* * * * * * * * * *
* * * * * * * * * *
* * * * * * * * * * *
* * * * * * * * * * * *
* * * * * * * * * * * * *
* * * * * * * * * * * * * *
* * * * * * * * * * * * * * *

Almost, yeah? Hahah. I can do this with numbers no problem.

xmas tree with numbers=


	public class ChristmasTrees
	{
		public static void main(String[] args)
		{
			int i,j;
				
				
		System.out.println("	Merry Christmas!!\n\n\n");	
				
				
				
				
			for (i = 1; i <=4; i++)
			{
				for (j = 1; j <= (12 - i); j++)
					System.out.print(" ");
				for (j = 1; j<= i; j++)
					System.out.print(j);
				for (j = (i - 1); j >= 1; j--)
					System.out.print(j);
				System.out.println("");
			}
			
			
			for (i = 3; i <=6; i++)
			{
				for (j = 1; j <= (12 - i); j++)
					System.out.print(" ");
				for (j = 1; j<= i; j++)
					System.out.print(j);
				for (j = (i - 1); j >= 1; j--)
					System.out.print(j);
				System.out.println("");
			}
			
			for (i = 5; i <=9; i++)
			{
				for (j = 1; j <= (12 - i); j++)
					System.out.print(" ");
				for (j = 1; j<= i; j++)
					System.out.print(j);
				for (j = (i - 1); j >= 1; j--)
					System.out.print(j);
				System.out.println("");
			}
			
			
		System.out.println("\n\n\n And a Happy New Year!!!");			
		}
		
	}


But asterisks are screwing with me >.<

Thanks in advance,

Mike

Is This A Good Question/Topic? 0
  • +

Replies To: Oh Christmas tree oh Christmas tree

#2 no2pencil  Icon User is online

  • Toubabo Koomi
  • member icon

Reputation: 5246
  • View blog
  • Posts: 27,063
  • Joined: 10-May 07

Re: Oh Christmas tree oh Christmas tree

Posted 06 November 2007 - 11:53 AM

http://www.dreaminco...mp;#entry270770
Was This Post Helpful? 0
  • +
  • -

#3 sgmikewoody  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 15
  • Joined: 30-September 07

Re: Oh Christmas tree oh Christmas tree

Posted 06 November 2007 - 05:25 PM

View Postno2pencil, on 6 Nov, 2007 - 11:53 AM, said:



I replaced System.out.print(j) with System.out.print("*") and it worked just fine.

Thanks! I'll have to try it your way as well.

Mike

This post has been edited by sgmikewoody: 06 November 2007 - 05:27 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1