日期:2014-05-20  浏览次数:20618 次

程序不能运行,请问该如何调试啊!
编译该程序可以通过,但在运行时提示说索引超出了范围,不管怎么调试问题依旧   该怎么改啊谢谢!
class   TestInteger
{
public   static   void   main(String[]   args){
int   w   =   Integer.parseInt(args[0]);
int   h   =   new   Integer(args[1]).intValue();
        for   (   int   i=0;   i <h;   i++   )
              {
              StringBuffer   sb=new   StringBuffer();
              for   (   int   j=0;   j <w;   j++   )
                {
                  sb.append( '* ');
                }
              System.out.println(sb.toString());
              }
        }
}


------解决方案--------------------
class TestInteger
{
public static void main(String[] args){
if(args.length!=2)
{
System.out.println( "Using TestInterger m n\n and m n must be Integer and larger than 0! ");
System.exit(-1);

}
int w = Integer.parseInt(args[0]);
int h = new Integer(args[1]).intValue();
for ( int i=0; i <h; i++ )
{
StringBuffer sb=new StringBuffer();
for ( int j=0; j <w; j++ )
{
sb.append( '* ');
}
System.out.println(sb.toString());
}
}
}