www.fltk.net > 用jAvA编写程序求n!

用jAvA编写程序求n!

import java.util.Scanner;public class Text{ public static void main(String args[]){ System.out.println("请输入n"); Scanner sc = new Scanner(System.in); int n= sc.nextInt(); int t=1; int i=1; while(i

import java.util.Scanner; public class A{ //下面的方法是对单个数求阶乘,并返回 public static int jieCheng(int n){ int sum=1; for(int i=1;i

import java.util.Scanner; //递归法求阶乘,eclipse编译通过 public class Test { public static void main(String srag[]){ int num = 0; while(true){ System.out.println("请输入一个正整数:"); Scanner sc = new Scanner(System.in); num = ...

需要的话,留个邮箱,一会写完发给你

完整代码如下,复制到eclipse中运行: public class Exam01 {// 下面的这个方法利用递归的方法求阶乘public int getFac(int m) {if (m == 1) {return 1;} else {return m * getFac(m - 1);}}public static void main(String args[]) {Exam01 fac...

public static BigInteger jiecheng(int n) {BigInteger bi = new BigInteger("1");while(n > 1) {bi = bi.multiply(new BigInteger(n + ""));n = n - 1;}return bi;}足够你算100以内的任何数的阶乘了

直接调用下面的函数就可以了。 displayNum(10); public static void displayNum(int num) { if (num > 1) { displayNum(num - 1); } System.out.println(num); }

public static void main(String[] args){ System.out.println("输入n,按回车:"); Scanner s = new Scanner(System.in); Integer n = Integer.parseInt(s.next()); Integer re = factorial(1, n); System.out.println(re); } public static I...

嘻嘻 ===================================== //for循环 打印1~n间的所有质数 import java.util.Scanner; public class ForExec2是质数{ public static void main(String[] args){ System.out.println("======》打印1~n间的所有质数《======")...

网站地图

All rights reserved Powered by www.fltk.net

copyright ©right 2010-2021。
www.fltk.net内容来自网络,如有侵犯请联系客服。zhit325@qq.com