如题所述
给个以前写的程序,自己改下就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("参数只能是正数!");
}
}
}
/**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("参数只能是正数!");
}
}
}
温馨提示:答案为网友推荐,仅供参考