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())//打印输出 }}public class Poly extends java.applet.Applet{int x[]={100,200,250,50,100}
int y[]={50,50,200,200,50}
public void paint (Graphics g){ ///////////////
int p=x.length
g.drawPolygon(x,y,p)
}
}