编写Java程序,判断用户输入的数字是否为正数,如果是则计算其阶乘
1个回答
展开全部
import java.util.*;
public class JieCheng{
public static void main(String[] args){
Scanner scanner = new Scanner(System.in);
while(scanner.hasNext()){
String str = scanner.next();
int zs = Integer.parseInt(str);
if(zs > 0){
int jc = 1;
for (int i = 1;i <= zs ;i++ ) {
jc *= i;
}
System.out.println(zs + "的阶乘为" + jc);
}
}
}
}
public class JieCheng{
public static void main(String[] args){
Scanner scanner = new Scanner(System.in);
while(scanner.hasNext()){
String str = scanner.next();
int zs = Integer.parseInt(str);
if(zs > 0){
int jc = 1;
for (int i = 1;i <= zs ;i++ ) {
jc *= i;
}
System.out.println(zs + "的阶乘为" + jc);
}
}
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询