• Post Reply Bookmark Topic Watch Topic
  • New Topic

how to print a christmas tree?  RSS feed

 
Lim Youjie
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi, im a newbie to java.

this program allows the user to input the height of the christmas tree.
but i m not sure of the codings for the loop.
e.g the height indicate by user is 4

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

e.g the height indicate by user is 3

*
***
*****
 
Martyn Clark
Ranch Hand
Posts: 108
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Lim i don't quite understand what you are trying to do with the loop and user input can you explain a little better or post some code.
 
Lim Youjie
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
Seb Mathe
Ranch Hand
Posts: 225
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
using char ast = '*';

you can do :

char[] line = new char[2*i-1];
java.util.Arrays.fill(line, c);
System.out.println(line);
[ October 11, 2005: Message edited by: Seb Mathe ]
 
Lim Youjie
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
may i know wats c?
thanks
 
Lim Youjie
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks think i understand Martyn Clark and Seb Mathe.
you guys are great.
 
Seb Mathe
Ranch Hand
Posts: 225
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
oops, "c" is "ast"

char c = '*';
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!