Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within Beginning Java
Search Coderanch
Advance search
Google search
Register / Login
Win a copy of
Communication Patterns: A Guide for Developers and Architects
this week in the
Design and Architecture
forum!
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Campbell Ritchie
Ron McLeod
Paul Clapham
Devaka Cooray
Liutauras Vilda
Sheriffs:
Jeanne Boyarsky
paul wheaton
Henry Wong
Saloon Keepers:
Stephan van Hulst
Tim Holloway
Tim Moores
Carey Brown
Mikalai Zaikin
Bartenders:
Lou Hamers
Piet Souris
Frits Walraven
Forum:
Beginning Java
how to print a christmas tree?
Lim Youjie
Greenhorn
Posts: 22
posted 18 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
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
posted 18 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
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.
Martyn...<br /> <br />SCJP 1.4 SCWCD 1.4
Lim Youjie
Greenhorn
Posts: 22
posted 18 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
import java.io.InputStreamReader; import java.io.BufferedReader; public class Tree { int height; int count; String ast = "*"; public Tree() { System.out.print("Enter height of christmas tree? "); try { InputStreamReader reader = new InputStreamReader(System.in); BufferedReader console = new BufferedReader(reader); String inStr = console.readLine(); height = Integer.parseInt(inStr); for (int i =1; i <= height; i++) { ......... ---> //codings to draw out the christmas tree } } catch(Exception ex) {} } public static void main(String[] args) { new Tree(); } }
Seb Mathe
Ranch Hand
Posts: 225
posted 18 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
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 ]
Regards,<br />Seb<br /> <br />SCJP 1.4
Lim Youjie
Greenhorn
Posts: 22
posted 18 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
may i know wats c?
thanks
Lim Youjie
Greenhorn
Posts: 22
posted 18 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
thanks think i understand Martyn Clark and Seb Mathe.
you guys are great.
Seb Mathe
Ranch Hand
Posts: 225
posted 18 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
oops, "c" is "ast"
char c = '*';
Regards,<br />Seb<br /> <br />SCJP 1.4
them good ole boys were drinking whiskey and rye singin' this'll be the day that I die. Drink tiny ad.
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
ascii pine trees
Another one from "Art and Science of Java"
I need help - basic stuff (I think)
Incorrect input causes endless loop?
calculation float problem, and alot of errors and been trying to fix this problems for days.
More...