import java.io.IOException;
import java.io.InputStream;
public class Digui {
/**
* @param args
*/
public static void main(String[] args) {
byte[] b = new byte[32];
while (true) {
try {
System.out.println("请输入正整数,获取其阶乘,输入over结束");
System.in.read(b);
String res = new String(b).trim();
if (res.equals("over")) {
System.out.println("程序结束");
break;
}
int i = Integer.parseInt(res.trim());
if (i <= 0)
continue;
System.out.println(i + "!=" + getResult(i));
} catch (IOException e) {
e.printStackTrace();
} catch (NumberFormatException ne) {
System.out.println("请输入正整数");
}
}
}
public static int getResult(int i) {
return i == 1 ? i : i * getResult(i - 1);
}
}
温馨提示:内容为网友见解,仅供参考