📄 exception7.java
字号:
//计算n!
public class Exception7
{
public static double multi(int n)
{
if (n < 0)
throw new IllegalArgumentException("输入了负数异常");
double s = 1;
for (int i=1; i<=n; i++)
s = s *i;
return s;
}
public static void main(String args[])
{
try
{
int n = Integer.parseInt(args[0]);
System.out.println( n + "!=" + multi(n));
}
catch (ArrayIndexOutOfBoundsException e)
{ System.out.println("应该输入一个整数"); }
catch (NumberFormatException e2)
{ System.out.println("应该输入一个数"); }
catch (IllegalArgumentException e3)
{ System.out.println("出现的异常为: "+e3.toString()); }
finally
{ System.out.println("计算阶乘结束");}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -