Categories

JAVA DATEBASE
Technology Network Community
Oracle Database
Fusion Middleware
Development Tools
Java
Desktop
Server & Storage Systems
Enterprise Management
Berkeley DB Family
Cloud Computing
Big Data
Business Intelligence
Architecture
Migration and Modernization
E-Business Suite
Siebel
PeopleSoft Enterprise
JD Edwards World
Industries
JD Edwards EnterpriseOne
User Productivity Kit Pro (UPK) and Tutor
Governance, Risk & Compliance (GRC)
Master Data Management (MDM)
Oracle CRM On Demand
On Demand: SaaS and Managed Applications
AutoVue Enterprise Visualization
Primavera
ATG
Agile PLM
Endeca Experience Management
Fusion Applications
Archived Forums

 



Tags

New To Java


how to print a christmas tree?


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      *    ***  *****

So what's your question? If it's "How do I do this? I have no idea," then you should speak to your instructor or engage a private tutor.  First describe, in very simple steps, how you'd do it without Java. Imagine you're giving instructions to somebody who's going to have to just take a number from you and then draw out the tree by hand. You only get to tell them once, and they can't ask questions, so you have to be as explicit and precise and clear as possible.  You have to be able to do that first before you can write it in Java.

My printer's too small for fir trees. I can't get it to print anything larger than a fern, and even that almost empties the chlorophyll cartridge.

A hint: You have to program a loop. Follow this tutorial to learn about loops: Learning the Java Language - Control Flow Statements

Hint.... numStars = line + (line - 1); indent = height - line;   You'll need two loops unless you use recursion - but I suspect recursion is in a future lesson.  Once you get some code togoether, post it and ask specific questions if you have problems.

Could someone please help me about write a small and easy programm to draw(println) this xmas tree; i have really no idea?? i can print already a half xmas tree with  for (int r = 1; r <= 6; r++) {  			for(int x = 1; x <= r; x++) { 				System.out.print("*");  			} 			System.out.println(""); this one but i have no idea how to create the left side???

System.out.println("A Christmas tree");   kind regards Walken16

Get out a piece of graph paper and draw a xmas tree with one * in each square. You should then notice that the number of spaces on each line (before you print an *) decreases while the number of * increase.

this one i know how to do!!! my question is if there will be 100000 or more ... how it will be??? if its 1000000 times, i dont wanna write all the time!!

and how can i decrease the blank??? with loops???  String blank="       " ?????  blank--

   public static void main (String args[])throws Exception {       int height = 20;         String s = "^";       for (int i=0; i<height; i++)       {              for (int j=0; j<(height-i); j++)          {             System.out.print(" ");          }          if (i==0)          {             System.out.println("*");          }          else          {             System.out.println(s);          }          s+="^^";       }    }   //This out put is /*                      *                    ^^^                   ^^^^^                  ^^^^^^^                 ^^^^^^^^^                ^^^^^^^^^^^               ^^^^^^^^^^^^^              ^^^^^^^^^^^^^^^             ^^^^^^^^^^^^^^^^^            ^^^^^^^^^^^^^^^^^^^           ^^^^^^^^^^^^^^^^^^^^^          ^^^^^^^^^^^^^^^^^^^^^^^         ^^^^^^^^^^^^^^^^^^^^^^^^^        ^^^^^^^^^^^^^^^^^^^^^^^^^^^       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^  */


Related Links

Hash Code
Interface question..
PL/JAVA
String
DefaultTableCellRenderer Need help with adding Icon to cell (right of text)
Scrollbars and awt.List
applet won't leave home
line by line checking
Need general advice on package selection regarding java
Removing a character using random access file copying [] problem
Non-Static 2
Best IDE?
GUI Interface to layout your windows
Silly Qs to ask
new to java: how to replace an image extending a JComponent?
j2me &#38; internet