
展开全部
import javax.swing.JOptionPane;
class Test {
public static long function(int n)throws Exception{
if(n==0){
return 1;
}else{
return n*function(n-1);
}
}
public static void main(String[] args)throws Exception {
String whole=JOptionPane.showInputDialog("请输入一个整数!");
int n=0;
long l=0;
try{
n=Integer.parseInt(whole);
if(n<1)
throw new NumberFormatException();
}catch(NumberFormatException e){
JOptionPane.showMessageDialog(null, "您输入的不是一个正整数!");
}
l= function(n);
JOptionPane.showMessageDialog(null,l);
}
}
class Test {
public static long function(int n)throws Exception{
if(n==0){
return 1;
}else{
return n*function(n-1);
}
}
public static void main(String[] args)throws Exception {
String whole=JOptionPane.showInputDialog("请输入一个整数!");
int n=0;
long l=0;
try{
n=Integer.parseInt(whole);
if(n<1)
throw new NumberFormatException();
}catch(NumberFormatException e){
JOptionPane.showMessageDialog(null, "您输入的不是一个正整数!");
}
l= function(n);
JOptionPane.showMessageDialog(null,l);
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |