Results 1 to 3 of 3
  1. #1
    Zeronitic is offline Member
    Join Date
    Jan 2012
    Posts
    9
    Rep Power
    0

    Default Could someone help me out with this?

    I'm in some need of some assistance in this since my knowledge of java is limited.
    I've been trying to make a tree like this.

    Tree

    This is what I have so far. Only the last three rows aren't finished.
    What should I change so the last three rows are 3 stars?
    Thanks if anyone can assist me.
    Java Code:
    public class pro50{
    	public static void main(String[] args){
    		final int col = 15;
    		final int row = 15;
    		int space = 0;
    		int counter = 1;
    		
    		while(counter <= row){
    			
    			if(counter % 2 != 0){
    				space = (col - counter)/2;
    				int x = 1;
    				while(x <= space){
    					System.out.print(" ");
    					x = x + 1;
    				}
    				x = 1;
    				while(x <= counter){
    					System.out.print("*");
    					x = x + 1;
    				}
    				counter = counter + 1;
    			}
    			else{
    				System.out.println();
    				counter = counter + 1;
    			}
    		}
    	}
    }

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: Could someone help me out with this?

    I would add a for loop that begins after your while loop has ended. It will loop 3 times, and inside of this for loop, have two additional for loops, one right after the other, the first for spaces, the second for stars.

    This part of your code will be easier than that which you've already done, so I'm betting that you'll be able to solve it in no time. Best of luck!

  3. #3
    Zeronitic is offline Member
    Join Date
    Jan 2012
    Posts
    9
    Rep Power
    0

    Default Re: Could someone help me out with this?

    Alright. Thanks. I'll give that a shot and see how it all works out.

Posting Permissions

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