zoukankan      html  css  js  c++  java
  • java内外循环打印等腰三角*号

    一.倒等腰  

      思路:三角形的左边,可看作空格,依次0个,1个,2个...。中间部分看做* ,星号和一个空格组成。

      

     1 class dayin 
     2 {
     3     public static void main(String[] args)
     4     {
     5         for(int x=0;x<5;x++)
     6         {
     7             for(int y=0;y<x;y++)
     8             {
     9                 System.out.print(" ");
    10             }
    11             for(int z=x;z<5;z++)
    12             {
    13                 System.out.print("* ");
    14             }
    15             System.out.println();
    16         }
    17     }
    18 }

    二.正等腰

     1 class dayin 
     2 {
     3     public static void main(String[] args)
     4     {
     5         for(int x=0;x<5;x++)
     6         {
     7             for(int y=4;y>x;y--)
     8             {
     9                 System.out.print(" ");
    10             }
    11             for(int z=0;z<=x;z++)
    12             {
    13                 System.out.print("* ");
    14             }
    15             System.out.println();
    16         }
    17     }
    18 }

    效果图:

  • 相关阅读:
    jsp4个作用域
    jsp9个内置对象
    jsp指令
    jsp注释
    jsp原理
    java面试
    代理
    泛型
    exception
    基础
  • 原文地址:https://www.cnblogs.com/gaigaichen/p/8259298.html
Copyright © 2011-2022 走看看