使用JAVA(嵌套for循环完成)用星号输出一个梯形

Python017

使用JAVA(嵌套for循环完成)用星号输出一个梯形,第1张

按照你的要求,编写的用星号输出一个梯形的Java程序如下

public class B {

 public static void main(String[] args) {

  int N=5

  for(int i=1i<=Ni++){

   for(int j=1j<=N-ij++){

    System.out.print(" ")

   }

   for(int j=1j<=2*i+1j++){

    System.out.print("*")

   }

   System.out.println()

  }

 }

}

运行结果

class Tixing //梯形类

{

private float Height//高

private float upBotton//上底

private float downBotton//下底

public Tixing(float Height,float upBotton,float downBotton)//构造方法

{

this.Height=Height

this.upBotton=upBotton

this.downBotton=downBotton

}

public float getTixingArea() //计算梯形面积

{

return (upBotton+downBotton)*height/2

}

}

public class Start

{

public static void main(String[] args)

{

Tixing t=new Tixing(30,20,50)//构造

System.out.println("梯形的面积是:"+t.getTixingArea())//打印输出

}

}