美文网首页
day09_三角形图案_99乘法表

day09_三角形图案_99乘法表

作者: 雷阳洪 | 来源:发表于2019-01-14 18:36 被阅读2次

    三角形图案

    public class TriangleDemo 
    {
        public static void main(String[] args) 
        {
            /*
                输出三角形图案
            */
            //SB版
            //System.out.println("☆");
            //System.out.println("☆☆");
            //System.out.println("☆☆☆");
            //System.out.println("☆☆☆☆");
            //System.out.println("☆☆☆☆☆");
            
            //2B版
            /*int j = 1;
            for (int i = 1;i <= j;i ++ )
            {
                System.out.println("☆");
            }
            j ++;
            for (int i = 1;i <= j;i ++ )
            {
                System.out.print("☆");
            }
            System.out.println();
            j ++;
            for (int i = 1;i <= j;i ++ )
            {
                System.out.print("☆");
            }
            System.out.println();
            j ++;
            for (int i = 1;i <= j;i ++ )
            {
                System.out.print("☆");
            }
            System.out.println();
            j ++;
            for (int i = 1;i <= j;i ++ )
            {
                System.out.print("☆");
            }
            */
            
            //优化版
            
            for (int j = 1;j <= 5 ; j ++ )
            {
                for (int i = 1;i <= j;i ++ )
                {
                    System.out.print("☆");
                }
                System.out.println();
            }
            
        }
    }
    

    99乘法表

    public class Table99Demo 
    //输出99乘法表
    /*
    System.out.println(1*1=1);
    System.out.println(1*2=2 2*2=4);
    System.out.println(1*3=3 2*3=6 3*3=9);
    */
    //规律:第二个乘数和行数相同,第一个乘数<=第二个乘数
    {
        public static void main(String[] args) 
        {
                //2B版
            /*
            int j = 1;
            for (int i =1;i <= j   ;i ++ )
            {
                System.out.print(i + "*" + j + "=" + (i * j));
            }
            System.out.println();
            j ++;
            for (int i =1;i <= j   ;i ++ )
            {
                System.out.print(i + "*" + j + "=" + (i * j) + " ");
            }
            System.out.println();
            j ++;
            for (int i =1;i <= j   ;i ++ )
            {
                System.out.print(i + "*" + j + "=" + (i * j) + " ");
            }
            System.out.println();
            */
            //优化版
            for (int j = 1;j <= 9 ;j ++ )
            {
                for (int i =1;i <= j;i ++ )
                {
                    System.out.print(i + "*" + j + "=" + (i * j) + " ");
                }
                System.out.println();
            }
        }
    }
    

    相关文章

      网友评论

          本文标题:day09_三角形图案_99乘法表

          本文链接:https://www.haomeiwen.com/subject/qhmjdqtx.html