Java Common 100 Cases

Source: Internet
Author: User

It is the true nature of the struggle to do a good deed to be held up by duty. --Balzac


The content of this lecture: 100 cases commonly used in Java


Example 1: Printing pyramids

public class T {public static void main (string[] args) {int lay=10;for (int i=1;i<=lay;i++) {///presentation layer for (int j=1;j<= lay-i;j++) {//Find out the space law System.out.print ("");} for (int k=1;k<=i*2-1;k++) {//Find out * regular System.out.print ("*");} System.out.println ();}}}
Results:

         *        ***       *****      *******     *********    ***********   *************  *************** ************ ************************


Example 2: Print an empty pyramid

public class T {public static void main (string[] args) {int lay=10;for (int. i=1;i<=lay;i++) {for (int j=1;j<=lay-i;j++ ) {System.out.print ("");} for (int k=1;k<=i*2-1;k++) {if (i==1| | I==lay) {//Determine if the layer is a top-level or low-System.out.print ("*");} Else{if (k==1| | k==i*2-1) {//First and last hit *system.out.print ("*");} Else{system.out.print ("");}} System.out.println ();}}}
Results:

         *        * *       *   *      *     *     *       *    *         *   *           *  *             * *               ********************



Java Common 100 Cases

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.