?? 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 + -