Print the positive/inverted triangle and the triangle

Source: Internet
Author: User

Print the positive/inverted triangle and the triangle

Package com. demo1; /*** print the positive/inverted triangle ** @ author denny the positive triangle changes the initialization value. The triangle changes the cycle condition. */public class Demo6 {public static void main (String [] args) {print (5); // inverted right triangle printzhen (4); // right triangle printZhenDenng (5); // positive waist triangle printDaoDenng (5 ); // inverted waist triangle} // inverted right triangle public static void print (int row) {System. out. println ("=========== inverted right triangle ======="); for (int x = 0; x <row; x ++) {for (int y = x + 1; y <row; y ++) {System. out. print ("*");} System. out. println () ;}}// public static void printzhen (int row) {System. out. println ("=========== normal right triangle ==============="); for (int x = 0; x <row; x ++) {for (int y = 0; y <= x; y ++) {System. out. print ("*");} System. out. println () ;}}// regular waist triangle public static void printZhenDenng (int row) {System. out. println ("=========== regular waist triangle =============="); for (int x = 0; x <row; x ++) {// control how many rows are displayed // control how many spaces are displayed for (int y = x + 1; y <row; y ++) {System. out. print ("") ;}// control how many digits are displayed for (int z = 0; z <= x; z ++) {System. out. print ("*");} System. out. println () ;}}// inverted waist triangle public static void printDaoDenng (int row) {System. out. println ("=========== waist triangle ============="); for (int x = 0; x <row; x ++) {// control how many rows are displayed // control how many spaces are displayed for (int y = 0; y <x; y ++) {System. out. print ("") ;}// control the number of * numbers displayed for (int z = x; z <row; z ++) {System. out. print ("*");} System. out. println ();}}}

 

 

============== Inverted right triangle =========********** ======== positive right Triangle ================*********** ========== regular waist triangle ==== ==========***************** ========== waist triangle ==== ======== ***************

 

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.