求java代码!!

2025-01-02 22:45:17
推荐回答(1个)
回答1:

关于递归算阶乘的importjava.math.BigDecimal;importjava.io.*;publicclassfactorial{//定义递归算阶乘方法publicstaticBigDecimalfac(intn){BigDecimalresult=newBigDecimal(n);if(n==1)returnresult;else{result=result.multiply(fac(n-1));returnresult;}}publicstaticvoidmain(String[]args)throwsIOException{BufferedReaderinput=newBufferedReader(newInputStreamReader(System.in));System.out.println("请输入一个数");intnum=Integer.parseInt(input.readLine());System.out.println(factorial.fac(num));}}问题二:importjava.util.Arrays;publicclassRandomNo{publicstaticvoidmain(String[]args){int[]num=newint[10];//可以根据自己的需要定义产生几个随机数System.out.println("产生的随机数为");for(inti=0;i<10;i++){num[i]=(int)(Math.random()*100);System.out.print(num[i]+"");}System.out.println();Arrays.sort(num);System.out.println("排序后的随机数为");for(inti=0;i<10;i++){System.out.print(num[i]+"");}}}