Java Prints the following pattern (diamond)

Source: Internet
Author: User

Topic:

Print out the case (diamond)

Program Analysis:

First, the graph is divided into two parts to see, the first four lines a rule, after three lines a rule, the use of double for loop, the first layer control row, the second Level control column.

Code section:
1  Public classprog18{2      Public Static voidMain (string[] args) {3         intn = 5;4 Printstar (n);5     }6     //Print stars7     Private Static voidPrintstar (intN) {8         //print top Half9          for(inti=0;i<n;i++){Ten              for(intj=0;j<2*n;j++){ One             if(j<n-i) ASystem.out.print (""); -             if(J>=n-i && j<=n+i) -System.out.print ("*"); the           } - System.out.println (); -         } -         //print the lower half of the section +          for(inti=1;i<n;i++){ -System.out.print (""); +              for(intj=0;j<2*n-i;j++){ A                 if(j<i) atSystem.out.print (""); -             if(J>=i && j<2*n-i-1) -System.out.print ("*"); -             } - System.out.println (); -         } in     } -}

Operation Result:
     *    ***   *****  ******* *********  *******   *****    ***     *

Java Print out the case (diamond)

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.