Java Fundamentals Hardening 07: Print out Hollow diamonds

Source: Internet
Author: User

1. Print out the Hollow Diamond :

2. The following is the logic implementation code:

1  Packagehimi.hebao04;2 3 ImportJava.util.Scanner;4 5  Public classTestDemo08 {6      Public Static voidMain (string[] args) {7         intlength = 1;//variable that stores the side length of a diamond8Scanner sc =NewScanner (system.in);//Scan object for input data9System.out.println ("Please enter the side length of the Diamond:");TenLength = Sc.nextint ();//gets the value of the edge length of the input One         /*print the top half of a diamond with a length line of triangles*/ A          for(inti = 1; I <= length; i++) {//number of lines to print -              for(intj = 1; J <= Length-i; J + +) {//print the left blank area, with the accompanying decrement 1 -System.out.print (""); the             } -              for(intK = 1; K <= 2 * i-1; k++) {//the area of the Triangle -                 if(k = = 1 | | k = = 2 * i-1) {//Hollow Fetch except for the first and last outer lines of each row are blank, the starting position is no longer 1 rows and 1 columns, because the front space prints the placeholder -System.out.print ("*"); +}Else { -System.out.print (""); +                 } A             } at System.out.println (); -         } -         /*print the lower half of a diamond triangle the middle row is common so the number of rows is Length-1*/ -          for(inti = length-1; i > 0; i--) { -              for(intj = 1; J <= Length-i; J + +) { -System.out.print (""); in             } -              for(intK = 1; K <= 2 * i-1; k++) { to                 if(k = = 1 | | k = = 2 * i-1) { +System.out.print ("*"); -}Else { theSystem.out.print (""); *                 } $             }Panax Notoginseng System.out.println (); -         } the     } +  A}

Java Fundamentals Hardening 07: Print out Hollow diamonds

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.