For loop output funnel shape "Java"

Source: Internet
Author: User

Use the FOR Loop statement to output the following funnel effect:

+------+|\..../|| \.. / ||  \/  ||  /\  || /.. \ || /....\|+------+

Code: (See the code header for more lines of comment)

In this example code, a constant height is used, which refers to half of the interior height value of the funnel as a constant value.

/** +------+ height:3 * |\..../| First line: Number of spaces: 0 Pips: 4 spaces: 0 * | \..     / |  Second line: Number of spaces: 1 pips: 2 spaces: 1 * |     \/  |  Third line: Number of spaces: 2 pips: 0 Spaces: 2 * | /\  | * | /.. \ | * |/....\|    * +------+ * * +--------+ height:4 * |\....../| First line: Number of spaces: 0 Pips: 6 spaces: 0 * |    \..../ |  Second line: Number of spaces: 1 pips: 4 spaces: 1 * | \..    /  |   Third line: Number of spaces: 2 pips: 2 spaces: 2 * |    \/   |   Line four: Number of spaces: 3 pips: 0 Spaces: 3 * | /\   |  * | /.. \  | * | /....\ | * |/......\|         * +--------+ * * Analysis: * 1, the graph is divided into three parts: *-the top and bottom of the graph; *-the upper part of the funnel *-the lower part of the funnel * 2, the upper part of the funnel is a fixed height * -Top and bottom graphics: * "-" Quantity: 2*height *-Funnel Upper part * Nth line: Number of spaces: line-1 points: (height-line              Number of spaces: line-1 *-bottom of funnel * Nth line: Number of spaces: Height-line points: (line-1) Number of spaces: Height-line * *  */ Public classTest { Public Static Final intHEIGHT = 3;  Public Static voidMain (string[] args) {drawLine ();        Drawtop ();        Drawbottom ();    DrawLine (); }         Public Static voidDrawtop () { for(intline=1;line<=height;line++) {System.out.print ("|"); //output to the right of the space ""                 for(intI=1;i<= (line-1); i++) {System.out.print (" "); } System.out.print ("\\"); //output point "."                 for(inti=1;i<=2* (height-line); i++) {System.out.print ("."); } System.out.print ("/"); //output to the right of the space ""                 for(inti=1;i<=line-1;i++) {System.out.print (" "); } System.out.println ("|"); }            }      Public Static voidDrawbottom () { for(intline=height;line>0;line--) {System.out.print ("|"); //output to the right of the space ""                 for(intI=1;i<= (line-1); i++) {System.out.print (" "); } System.out.print ("/"); //output point "."                 for(inti=1;i<=2* (height-line); i++) {System.out.print ("."); } System.out.print ("\\"); //output to the right of the space ""                 for(inti=1;i<=line-1;i++) {System.out.print (" "); } System.out.println ("|"); }            }          Public Static voidDrawLine () {System.out.print ("+");  for(inti=1;i<=2*height;i++) {System.out.print ("-"); } System.out.println ("+"); }}

The Code results show:

For loop output funnel shape "Java"

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.