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.

Page 2 of 2 FirstFirst 12
Results 26 to 27 of 27

Thread: Print out a triangle by character *

  1. #26
    Junior Member
    Join Date
    Aug 2012
    Posts
    13
    Thanks
    6
    Thanked 0 Times in 0 Posts

    Default Re: Print out a triangle by character *

    Quote Originally Posted by Norm View Post
    Please explain what is wrong with the spaces.


    Does that give you the right output?


    Thank you very much, you are so cool . I did it after some papers. I'm so happy. Now I understand the feeling of solving a problem by working through it. Thank you many times.


    public static void main(String[] args) {
    		int n = 4;
    		for(int i =0; i<n;i++){
    			for (int j = i; j <n; j++) {
    				//System.out.print(i);
    				System.out.print(" ");
    			}
    			for (int j = 0; j <2*i + 1; j++) {
    				System.out.print("*");
    			}
    			 System.out.println();
    		}
    	}

  2. #27
    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: Print out a triangle by character *

    Glad you got it to work.
    If you don't understand my answer, don't ignore it, ask a question.

  3. The Following User Says Thank You to Norm For This Useful Post:

    Genky (September 5th, 2012)

Page 2 of 2 FirstFirst 12

Similar Threads

  1. help with loop to print an equliateral asterisk triangle
    By everyone0 in forum Loops & Control Statements
    Replies: 13
    Last Post: October 11th, 2012, 12:37 PM
  2. xfa.host.print: print a page + some page range.
    By gammaman in forum Totally Off Topic
    Replies: 2
    Last Post: May 10th, 2012, 08:07 AM
  3. [HELP] TRIANGLE!
    By kramista in forum Loops & Control Statements
    Replies: 10
    Last Post: July 29th, 2010, 12:58 PM
  4. ASCII Triangle
    By physics in forum Loops & Control Statements
    Replies: 1
    Last Post: March 27th, 2010, 06:39 AM
  5. The character '' is an invalid XML character exception getting
    By sumanta in forum What's Wrong With My Code?
    Replies: 5
    Last Post: January 9th, 2010, 12:13 PM