……

图形计算

一.三角形
package 三角形.等腰图像;
public class Test {
    public static void main(String[] args) {
        Test1 test1=new Test1(5);
        Test1.one();
    }
}
class Test1
{
    public Test1(int num) {
        this.num = num;
    }
    static int num;
    public static void one()
    {
        for(int i=1;i<=num;i++)
        {
            for(int j=1;j-i<=num-1;j++)
            {
                if(i+j<=num)
                {
                    System.out.print(" ");
                }
                else{
                    System.out.print("*");
                }
            }
            System.out.println();
        }
    }
}

 

二.直角三角形图形
package 三角形.直角三角形;

/**
 * 总结:需要加空格的for下标从1开始
 */
public class One {
    public static void main(String[] args) {
        Test test = new Test(5);
        test.one();
        System.out.println("++++++++++++++++++++++++++++++");
        test.two();
        System.out.println("++++++++++++++++++++++++++++++");
        test.three();
        System.out.println("++++++++++++++++++++++++++++++");
        test.four();
    }
}

class Test {
    int num;

    public Test(int num) {
        this.num = num;
    }

    public void one() {
        for (int i = 1; i <= num; i++) {
            for (int j = 1; j <= i; j++) {
                System.out.print("*");
            }
            System.out.println();
        }
    }

    public void two() {
        for (int i = 0; i < num; i++) {
            for (int j = 0; j < num - i; j++) {
                System.out.print("*");
            }
            System.out.println();
        }
    }

    public void three() {
        for (int i = 1; i <= num; i++) {
            for (int j = 1; j <= num; j++) {
                if (i + j <= num) {
                    System.out.print(" ");
                } else
                    System.out.print("*");
            }
            System.out.println();
        }
    }

    public void four() {
        for (int i = 1; i <= num; i++) {
            for (int j = 1; j <= num; j++) {
                if (i > j) {
                    System.out.print(" ");
                } else {
                    System.out.print("*");
                }
            }
            System.out.println();
        }
    }
}

 

三.平行四边形
package 三角形.平行四边形;
public class Test {
    public static void main(String[] args) {
        One one=new One(5);
        one.one();
        System.out.println("++++++++++++++++++++++++++++++");
        one.two();
    }
}
class One
{
    int num;
    public void two()
    {
        for (int i=1;i<=num;i++)
        {
            for(int j=1;j-i<=num-1;j++)
            {
                if(i>j)
                {
                    System.out.print(" ");
                }
                else
                {
                    System.out.print("*");
                }
            }
            System.out.println();
        }
    }
    public void one()
    {
        for(int i=1;i<=num;i++)
        {
            for(int j=1;i+j<=2*num;j++)
            {
                if(i+j<=num) {
                    System.out.print(" ");
                }
                else
                {
                    System.out.print("*");
                }
            }
            System.out.println();
        }
    }
    public One(int num) {
        this.num = num;
    }
}
四.梯形
package 三角形.梯形;
public class Test {
    public static void main(String[] args) {
        Test1 test1=new Test1(5);
        test1.one();
        System.out.println("++++++++++++++++++++++++++++++");
        test1.two();
        System.out.println("++++++++++++++++++++++++++++++");
        test1.three();
        System.out.println("++++++++++++++++++++++++++++++");
        test1.four();
        System.out.println("++++++++++++++++++++++++++++++");
    }
}
class Test1
{
    int num;

    public Test1(int num) {
        this.num = num;
    }
    public void one()
    {
       for(int i=0;i<num;i++)
       {
           for(int j=0;j<i+num;j++)
           {
               System.out.print("*");
           }
           System.out.println();
       }
    }
    public void two()
    {
        for(int i=0;i<num;i++)
        {
            for(int j=0;j<2*num-i;j++)
            {
                System.out.print("*");
            }
            System.out.println();
        }
    }
    public void three()
    {
        for (int i=1;i<=num;i++) {
            for (int j = 1; j <= 2*num; j++) {
                if (i + j <= num) {
                    System.out.print(" ");
                } else {
                    System.out.print("*");
                }
            }
            System.out.println();
        }
    }
    public void four()
    {
        for(int i=1;i<=num;i++)
        {
            for(int j=1;j<=2*num;j++)
            {
                if(i>j)
                {
                    System.out.print(" ");
                }
                else
                {
                    System.out.print("*");
                }
            }
            System.out.println();
        }
    }
}
 posted on 2020-05-20 17:41  大码王  阅读(499)  评论(0编辑  收藏  举报
复制代码