Java print pyramid or print a pyramid with numbers (Small records in Java learning)

Source: Internet
Author: User

java print pyramid or print a pyramid with numbers (Small records in Java learning) Wang Coli (Star star)

The code is as follows:

1 classStar82 {3      Public Static voidMain (string[] args)4     {5         /*Space6 * 1 2*i-1 3 4-1 4-i7 * * * 3 2 4-28 * * * * 5 1 4-39 ******* 7 0 4-4Ten         */ One         //the first layer of loop control is the number of rows A          for(inti = 1;i<=5;i++){ -          -             //number of spaces to print the  -              for(intj=5;j>i;j--){ -                  -System.out.print (""); +             } -  +             //Print * Numbered A              for(intJ =1;j<=2*i-1;j++){ atSystem.out.print ("*"); -             } -  -             //line Break - System.out.println (); -         } -     } to}

The code is as follows:

1 classStar82 {3      Public Static voidMain (string[] args)4     {5         /*            6 1 i= 1 07 1 i= 2 18 123 i= 3 29 1234 321 i= 4 3Ten 12345 4321 One 123456 54321 A         */ -         //control number of rows -          for(inti = 1; i<=6; i++){ the  -             //Print a space -              for(intJ= 1; j<=6-i;j++){ -                  +System.out.print (""); -             } +          A             //Printing numbers: The law of the preceding numbers at              for(intj=1;j<=i;j++){ -              - System.out.print (j); -             } -  -             //the law of the numbers behind in              for(intj=i-1;j>=1;j--){ -              to System.out.print (j); +             } -      the System.out.println (); *         } $     }Panax Notoginseng}

Java print pyramid or print a pyramid with numbers (Small records in Java learning)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.