• 首页 首页 icon
  • 工具库 工具库 icon
    • IP查询 IP查询 icon
  • 内容库 内容库 icon
    • 快讯库 快讯库 icon
    • 精品库 精品库 icon
    • 问答库 问答库 icon
  • 更多 更多 icon
    • 服务条款 服务条款 icon

JAVA各个方向的三角形

武飞扬头像
phoenix1112
帮助1

Java实现正立,左上方,左下方,右上方,右下方,倒立,六个方向的三角形(下附上源代码)

  1.  
    public static void main(String[] args) {
  2.  
    // TODO Auto-generated method stub
  3.  
    System.out.println("左上方三角形");
  4.  
    for(int i=1;i<=8;i ){
  5.  
    for(int j=1;j<=i;j ){
  6.  
    System.out.print("*");
  7.  
    }
  8.  
    System.out.println();
  9.  
    }
  10.  
    System.out.println("---------------------------------------");
  11.  
    System.out.println("左下方三角形");
  12.  
    for(int i=1;i<=8;i ){
  13.  
    for(int j=1;j<=(8 1-i);j ){
  14.  
    System.out.print("*");
  15.  
    }
  16.  
    System.out.println();
  17.  
    }
  18.  
    System.out.println("---------------------------------------");
  19.  
    System.out.println("右上方三角形");
  20.  
    for(int i=1;i<=8;i ){
  21.  
    for(int j=1;j<(8 1-i);j ){
  22.  
    System.out.print(" ");
  23.  
    }
  24.  
    for(int j=i;j>0;j--){
  25.  
    System.out.print("*");
  26.  
    }
  27.  
    System.out.println();
  28.  
    }
  29.  
    System.out.println("---------------------------------------");
  30.  
    System.out.println("右下方三角形");
  31.  
    for(int i=0;i<8;i ){
  32.  
    for(int j=1;j<=i;j ){
  33.  
    System.out.print(" ");
  34.  
    }
  35.  
    for(int j=(7 1-i);j>0;j--){
  36.  
    System.out.print("*");
  37.  
    }
  38.  
    System.out.println();
  39.  
    }
  40.  
    System.out.println("---------------------------------------");
  41.  
    System.out.println("正立三角形");
  42.  
    for (int i = 1; i <=8; i ) {
  43.  
    for (int j = 1; j <(8 1-i); j ) {
  44.  
    System.out.print(" ");
  45.  
    }
  46.  
    for (int j = i; j >0; j--) {
  47.  
    System.out.print("*" " ");
  48.  
    }
  49.  
    System.out.println();
  50.  
    }
  51.  
    System.out.println("---------------------------------------");
  52.  
    System.out.println("倒立三角形");
  53.  
    for (int i = 8; i >0; i--) {
  54.  
    for (int j = 0; j < 8-i; j ) {
  55.  
    System.out.print(" ");
  56.  
    }
  57.  
    for (int j = i; j >0; j--) {
  58.  
    System.out.print("*" " ");
  59.  
     
  60.  
    }
  61.  
    System.out.println();
  62.  
    }
  63.  
    }
学新通

运行效果图如下:

左上方三角形
*
**
***
****
*****
******
*******
********
---------------------------------------
左下方三角形
********
*******
******
*****
****
***
**
*
---------------------------------------
右上方三角形
       *
      **
     ***
    ****
   *****
  ******
 *******
********
---------------------------------------
右下方三角形
********
 *******
  ******
   *****
    ****
     ***
      **
       *
---------------------------------------
正立三角形
       * 
      * * 
     * * * 
    * * * * 
   * * * * * 
  * * * * * * 
 * * * * * * * 
* * * * * * * * 
---------------------------------------
倒立三角形
* * * * * * * * 
 * * * * * * * 
  * * * * * * 
   * * * * * 
    * * * * 
     * * * 
      * * 
       * 
 

这篇好文章是转载于:学新通技术网

  • 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
  • 本站站名: 学新通技术网
  • 本文地址: /boutique/detail/tanhhaefaa
系列文章
更多 icon
同类精品
更多 icon
继续加载