Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 6 of 6

Thread: How to make this triangle upside down in java?

  1. #1
    Member
    Join Date
    Oct 2013
    Posts
    30
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default How to make this triangle upside down in java?

    class upsidedown {
    	public static void main(String args[]){
    		 int x,y;
    		    for (y= 1; y <= 5; y++)
    		    {
    		        for (x= 0; x < 5-y; x++)
    		            System.out.print(' ');
    		        for (x= (2-y); x < (2-y)+(2*y-1); x++)
    		            System.out.print('*');
    		        System.out.print('\n');
    		    }
    	}
    }
    So far this only prints a normal triangle, how can I make it upside down?


  2. #2
    Grand Poobah
    Join Date
    Mar 2011
    Posts
    1,545
    My Mood
    Grumpy
    Thanks
    0
    Thanked 167 Times in 158 Posts

    Default Re: How to make this triangle upside down in java?

    It would help if you provided an example of the output.

    Anyway, loops generally go from 0 upwards. What happens if you start at n and go downwards?
    Improving the world one idiot at a time!

  3. #3
    Member
    Join Date
    Oct 2013
    Posts
    30
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: How to make this triangle upside down in java?

    output is this:

  4. #4
    Grand Poobah
    Join Date
    Mar 2011
    Posts
    1,545
    My Mood
    Grumpy
    Thanks
    0
    Thanked 167 Times in 158 Posts

    Default Re: How to make this triangle upside down in java?

    My previous advice still applies. You have to work out how many spaces and stars need to printed on each line. And those values will decrease for stars and increase for spaces.
    Improving the world one idiot at a time!

  5. #5
    Member
    Join Date
    Oct 2013
    Posts
    30
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: How to make this triangle upside down in java?

    *

  6. #6
    Member GoodbyeWorld's Avatar
    Join Date
    Jul 2012
    Location
    Hidden command post deep within the bowels of a hidden bunker somewhere under a nondescrip building
    Posts
    161
    My Mood
    Stressed
    Thanks
    14
    Thanked 25 Times in 25 Posts

    Default Re: How to make this triangle upside down in java?

    Go in reverse.

    Start with where you stopped in the upwards one and end with where you started in the upwards one.

Similar Threads

  1. java triangle programming
    By babbigoyal in forum What's Wrong With My Code?
    Replies: 1
    Last Post: December 10th, 2012, 08:36 AM
  2. Triangle Printing - Java Program
    By mparthiban in forum Java Programming Tutorials
    Replies: 1
    Last Post: January 5th, 2012, 10:00 AM
  3. [HELP] TRIANGLE!
    By kramista in forum Loops & Control Statements
    Replies: 10
    Last Post: July 29th, 2010, 12:58 PM
  4. Triangle Printing - Java Program
    By mparthiban in forum Java Code Snippets and Tutorials
    Replies: 0
    Last Post: January 18th, 2010, 05:35 AM
  5. Triangle Question
    By Leeds_Champion in forum What's Wrong With My Code?
    Replies: 0
    Last Post: October 29th, 2009, 11:33 PM