PPT题目
1 //生成一千个随机数 2 public class LinearCongruentialGenerator { 3 private static final long MODULUS = 2147483647; // 2^31 - 1 4 private static final long MULTIPLIER = 75; 5 private static final long INCREMENT = 0; 6 7 private long state; 8 9 public LinearCongruentialGenerator(long seed) { 10 this.state = seed; 11 } 12 13 public int nextRandomInt() { 14 state = (MULTIPLIER * state + INCREMENT) % MODULUS; 15 return (int) state; 16 } 17 18 public static void main(String[] args) { 19 int numberOfRandomInts = 1000; 20 21 LinearCongruentialGenerator generator = new LinearCongruentialGenerator(System.currentTimeMillis()); 22 23 for (int i = 0; i < numberOfRandomInts; i++) { 24 int randomInt = generator.nextRandomInt(); 25 System.out.println(randomInt); 26 } 27 } 28 } 29 //用递归求一个数的阶乘 30 public class FactorialCalculator { 31 32 public static long calculateFactorial(int n) { 33 if (n == 0 || n == 1) { 34 return 1; 35 } else { 36 return n * calculateFactorial(n - 1); 37 } 38 } 39 40 public static void main(String[] args) { 41 int number = 5; // 替换为您要计算阶乘的整数 42 long factorial = calculateFactorial(number); 43 System.out.println(number + "的阶乘是:" + factorial); 44 } 45 }
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?