编写一个能输出由任意行*构成的三角形的自定义函数void sjx(int m),要求:在主函数中指定三角形的行?

如题所述

给个以前写的程序,自己改下就OK了

/**Arctangle.java
//import NoParamException;
@author zhuwenqing
@version 1.0(beta)*/
public class Arctangle
{
/**
get the height of Arctangle
@throws throws a exception
@param args get a param from screen
*/
public static int getHeight(String[] args)
throws NoParamException
{
int height;
if (args.length!=1) {throw new NoParamException("参数出错",80); }
height=Integer.parseInt(args[0]) ;
return height;
}

public static void main(String args[])
{
int height;

try
{
height=Arctangle.getHeight(args);
for(int i=0;i<height;i++)
{
for (int j=0;j<height-1-i;j++)
System.out.print(" ");
for(int k=height-i;k<=height+i;k++)
System.out.print("*");
System.out.println("");
}

}catch(NoParamException e)
{
System.out.println("必须有且只有一个整形参数");
} catch(NumberFormatException e)
{
System.out.println("参数只能是正数!");

}

}

}
温馨提示:答案为网友推荐,仅供参考

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网