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 2 of 2

Thread: Invert an integer Triangle?

  1. #1
    Junior Member
    Join Date
    Sep 2013
    Posts
    22
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Invert an integer Triangle?

    Hi all,

    I'm finding it difficult to get my head around the concept, but i managed to construct this for a section of my weekly assignment.

    class Q4d
    {
    public static void main (String [] args)
    	{
    	int numberOfLines = 6;
    	// Pattern D
    	System.out.println();
    	System.out.println("Pattern D");
    	//Getting correct number of rows
    	for (int lines = 1; lines <= numberOfLines; lines++)
    		{
    		//getting correct number of columns
    		for (int columns = 1; columns <= numberOfLines - lines; columns++) 
    			{
    			System.out.print("  ");
    			}
    		//getting figures
    		for (int number = 1; number <= lines; number++)
    			{
    			System.out.print(number + " ");
    			}
    		System.out.println();
    		}
    	}
    }
     
    Output = 
     
    Pattern D
    * * * * * 1 
    * * * * 1 2 
    * * * 1 2 3 
    * * 1 2 3 4 
    * 1 2 3 4 5 
    1 2 3 4 5 6




    The next question is asking me to present the same thing, only upside down.

    I'm not sure on how to do this.

    Any pointers in the right direction?


  2. #2
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,520
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: Invert an integer Triangle?

    So it should look like this?:
    1 2 3 4 5 6
      1 2 3 4 5
        1 2 3 4
          1 2 3
            1 2
              1
    (That was hard to do.)

    You can certainly print the first line. What has to happen after that?

Similar Threads

  1. help me draw a triangle....
    By beandip408 in forum Object Oriented Programming
    Replies: 10
    Last Post: October 28th, 2010, 05:49 PM
  2. [HELP] TRIANGLE!
    By kramista in forum Loops & Control Statements
    Replies: 10
    Last Post: July 29th, 2010, 12:58 PM
  3. How to invert?
    By ah207696 in forum Java Theory & Questions
    Replies: 1
    Last Post: November 3rd, 2009, 07:13 PM
  4. How to invert a word String
    By Truffy in forum Java Programming Tutorials
    Replies: 16
    Last Post: October 3rd, 2009, 02:44 AM
  5. How to invert a word String
    By Truffy in forum Java Code Snippets and Tutorials
    Replies: 16
    Last Post: October 3rd, 2009, 02:44 AM