JDK报错:无法将FactorialException中的calculate应用于o1.calculate
该怎么该
class JudgeException extends Exception
{
JudgeException()
{
System.out
JDK报错:无法将FactorialException中的calculate应用于o1.calculate
该怎么该
class JudgeException extends Exception
{
JudgeException()
{
System.out.println("数据不能为负数");
}
}
class FactorialException
{
void calculate(String a[])
{
int factorial=1;
int num;
try
{
num=Integer.parseInt(a[0]);
if(num<=0)
{
throw new JudgeException();
}
for(int i=1;i<=num;i++)
{
factorial*=i;
}
System.out.println("factorial="+factorial);
}
catch(JudgeException je)
{
System.out.println("输入的数据无效");
}
catch(ArrayIndexOutOfBoundsException ae)
{
System.out.println("数据不完整");
}
catch(NumberFormatException ne)
{
System.out.println("输入的数据不是数字");
}
catch(IllegalArgumentException ie)
{
System.out.println("输入的数据不合法");
}
}
}
public class FactorialExceptionTest
{
public static void main(String args[])
{
FactorialException o1=new FactorialException();
o1.calculate(args[0]);
}
}
展开
全部