展开全部
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);
}
}
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);
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询