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: Inverted Equilatieral Triangle (Asterisks) - Not Equilateral :-(

  1. #1
    Junior Member
    Join Date
    Oct 2011
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Inverted Equilatieral Triangle (Asterisks) - Not Equilateral :-(

    My assignment is to write a program that asks for the number of lines and then prints an inverted equilateral triangle across the number of lines. As far as I can see this program isn't printing the spaces properly and thus it is printing a right angled triangle and I don't know why. Can anybody help?
    Thanks in advance

    public class TestCW
    {
       public static void main (String [] args)
    	{
    	System.out.println ("Enter number");
    	int input, var1, var2, var3;
    	input = KBInput.readInt();
     
    	for (var1 = input; var1 >= 0; var1 --)
    	{
    	   System.out.println();
    		   for (var2 = var1; var2 < var1; var2 ++)
    			{
    				System.out.print(" ");
    			}
    			for (var3 = (var1 * 2 - 1); var3 > 0; var3 --)
    			{
    				System.out.print("*");
    			}
    	}
    	}
    }


  2. #2
    Junior Member
    Join Date
    Oct 2011
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Inverted Equilatieral Triangle (Asterisks) - Not Equilateral :-(

    Solved now, never mind

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. Equilateral Triangle Using nested for loop
    By uchizenmaru in forum Loops & Control Statements
    Replies: 2
    Last Post: January 14th, 2010, 10:01 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