One, Java loop control statement practice

Source: Internet
Author: User

1 //Note: Hao2 //function: Display pyramids on the console3 //Date: 2018.08.094 5  Public classtriangle{6      Public Static voidMain (String args[]) {7         intlay=10, i,j,k;8          for(i=1;i<=lay;i++){9              for(k=1;k<=lay-i;k++){TenSystem.out.print (""); One             } A              for(j=1;j<= (i-1) *2+1;j++){ -System.out.print ("*"); -             } the System.out.println (); -         } -     }  -}

Operation Result:

1 //Note: Hao2 //function: Skeleton pyramid displayed on the console3 //Date: 2018.08.094 5  Public classkongtriangle{6      Public Static voidMain (String args[]) {7         intlay=10, i,j,k,m;8          for(i=1;i<=lay;i++){9              for(k=1;k<=lay-i;k++){TenSystem.out.print (""); One             } A              for(j=1;j<= (i-1) *2+1;j++){ -                 if(i==1| | i==lay) { -System.out.print ("*");  the                 } -                 Else{ -                     if(j==1| | j== (i-1) *2+1){ -System.out.print ("*"); +                     } -                     Else{ +System.out.print (""); A                     } at                 } -             } - System.out.println (); -         } -     }  -}

Operation Result:

1 //Note: Hao2 //function: Display the diamond on the console3 //Date: 2018.08.094 5  Public classdiamond{6      Public Static voidMain (String []args) {7         intlay=10, i,j,k;8         //Upper Part 9 Floor9          for(i=1;i<=lay-1;i++){Ten              for(k=1;k<=lay-i;k++){ OneSystem.out.print (""); A             } -              for(j=1;j<= (i-1) *2+1;j++){ -System.out.print ("*"); the             } - System.out.println (); -         } -         //lower half 10 layers +          for(i=1;i<=lay;i++){ -              for(k=1;k<=i-1;k++){ +System.out.print (""); A             } at              for(j=1;j<= (lay-i) *2+1;j++){ -System.out.print ("*");  -             }             - System.out.println (); -         } -     } in } -         

Operation Result:

1 //Note: Hao2 //function: Display Hollow diamond on the console3 //Date: 2018.08.104 5  Public classkongdiamond{6      Public Static voidMain (String []args) {7         intlay=10, i,j,k;8         //Upper Part 9 Floor9          for(i=1;i<=lay-1;i++){Ten              for(k=1;k<=lay-i;k++){ OneSystem.out.print (""); A             } -              for(j=1;j<= (i-1) *2+1;j++){ -                 if(j==1| | j== (i-1) *2+1){ theSystem.out.print ("*");  -}Else{ -System.out.print (""); -                 } +             } - System.out.println (); +         } A         //lower half 10 layers at          for(i=1;i<=lay;i++){ -              for(k=1;k<=i-1;k++){ -System.out.print (""); -             } -              for(j=1;j<= (lay-i) *2+1;j++){ -                 if(j==1| | j== (lay-i) *2+1){ inSystem.out.print ("*");  -}Else{ toSystem.out.print (""); +                 } -             }             the System.out.println (); *         } $     }Panax Notoginseng } - 

Operation Result:

One, Java loop control statement practice

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.