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

Thread: Inverted Right Triangle

  1. #1
    Junior Member
    Join Date
    Mar 2013
    Posts
    6
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Inverted Right Triangle

    Making a much larger program with a menu to determine what * triangle you would like but can not get the triangle like this to work:

    **********
    -*********
    --********
    ---*******
    ----******
    -----*****
    ------****
    -------***
    -------- **
    ----------*

    Without the " - "
    It keeps printing out in a straight line be grateful if someone could point me in the right direction.
    public class tester
    {
        public static void main(String[] args)
        {
          final int x = 10;
          for (int row = 0; row < x; row ++){
            for (int blank = 1; blank <= row; blank ++){
              System.out.print (" ");
            }
            for (int a = x - row; a > 0; a --){
              System.out.print ("*");
            }
            }
    }
    }
    Last edited by KillerToFu; March 28th, 2013 at 10:20 PM. Reason: oops put in wrong code


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Inverted Right Triangle

    It keeps printing out in a straight line
    Call the println() method to have the next String go on the next line
    Or print a "\n" character to have the following String go on the next line.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Mar 2013
    Posts
    6
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: Inverted Right Triangle

    public class tester
    {
        public static void main(String[] args)
        {
     
            for (int i = 0; i < 10; i++) {
                for (int j = 0; j < i; j++)
                    System.out.print(" ");
                for (int j = i; j < 10; j++)
                    System.out.print("*");
                System.out.println();
            }
        }
    }{

    Made this work the way I wanted Thank you for the help.
    Trying to put it into my joptionpane string now but cant get it to convert right keeps printing out a straight line.

        for ( x4 = 0; x4 < 10; x4++) {
                for (  y4 = 0; y4 < x4; y4++)
                    o4 = o4 + " ";
                for ( y4 = x4; y4 < 10; y4++)
                    o4 = o4 + sFirst;
                     }

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Inverted Right Triangle

    Add a "\n" to the String where you want the next String on the next line.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Inverted Equilatieral Triangle (Asterisks) - Not Equilateral :-(
    By HapticThreek in forum What's Wrong With My Code?
    Replies: 1
    Last Post: October 20th, 2011, 05:03 PM
  2. help me draw a triangle....
    By beandip408 in forum Object Oriented Programming
    Replies: 10
    Last Post: October 28th, 2010, 05:49 PM
  3. [HELP] TRIANGLE!
    By kramista in forum Loops & Control Statements
    Replies: 10
    Last Post: July 29th, 2010, 12:58 PM
  4. [SOLVED] Java program to invert a string and display the last enter key in uppercase
    By chronoz13 in forum What's Wrong With My Code?
    Replies: 9
    Last Post: August 27th, 2009, 02:33 AM
  5. wheres the thread about inverted String?
    By chronoz13 in forum Java Theory & Questions
    Replies: 5
    Last Post: July 29th, 2009, 11:13 AM