Results 1 to 2 of 2
  1. #1
    IisDev is offline Member
    Join Date
    Oct 2016
    Posts
    1
    Rep Power
    0

    Default Christmas tree with decorations

    Hello all! In my computer science class, we were told to use the System.out.println(); command with nested for loops to print out a Christmas tree. I have the tree and trunk of the tree printed with * as we are supposed to. After that we need to use % and ^ to decorate the tree. The decorations are supposed to be placed randomly, and that is the part I cannot figure out. Any help would be great! Here is the code I have that works to print the Christmas tree without decorations:

    Java Code:
    public class thinking {
    
    	public static void main(String[] args) {
    		String a = "";
    		String b = "";
    		String c = "";
    
    		for (int i = 0; i < 4; i++) {
    			for (int j = 23; j >= i; j--) {
    				a = a + " ";
    			}
    			for (int k = 1; k < i * 2; k++) {
    				a = a + "*";
    			}
    			System.out.println(a);
    			a = "";
    		}
    		for (int i = 3; i > 0; i -= 2) {
    			for (int j = 0; j < 23 - i / 2; j++) {
    				a = a + " ";
    			}
    
    			for (int j = 0; j < i; j++) {
    				a = a + "*";
    			}
    			System.out.println(a);
    			a = "";
    		}
    		for (int d = 0; d < 22; d++) {
    			for (int e = 22; e >= d; e--) {
    				a = a + " ";
    			}
    			for (int f = 0; f < d * 2 + 1; f++) {
    				a = a + "*";
    			}
    			System.out.println(a);
    			a = "";
    		}
    		for (int i = 0; i < 2; i++) {
    			for (int e = 21; e >= i / 2; e--) {
    				a = a + " ";
    			}
    			for (int j = 0; j < 3; j++) {
    				a = a + "*";
    			}
    			System.out.println(a + b);
    			a = "";
    		}
    
    	}
    
    }

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    20,003
    Rep Power
    33

    Default Re: Christmas tree with decorations

    If you don't understand my response, don't ignore it, ask a question.

Similar Threads

  1. Replies: 3
    Last Post: 10-04-2013, 12:11 PM
  2. Synth Look And Feel - Window Decorations
    By neptune692 in forum AWT / Swing
    Replies: 0
    Last Post: 01-15-2011, 12:51 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •