/计算位数 计算阶乘 计算1!+2!+3!+··· 计算1-1/3!+1/5!+··· 计算pi pi/4=1-1/3+1/5+··· 逆置字符串 将十进制转为十六进制/ public class pra{ public static int countNum(int n){ int count=0; for(;n>0;n=n/10){ count++; } return count; } public static int factorial(int n){ if(n==1|n==0){ return 1; }else{ return nfactorial(n-1); } } public static int addFactorial(int n){ int sum=0; for(int i=1;i<=n;i++){ sum=sum+factorial(i); } return sum; } public static double plusOrMinusAdd(int n){ double sum=0.0; int j=1; for(int i=1;i<=n;i=i+2){ sum=sum+j(1.0/factorial(i)); j=j*-1; } return sum; } public static double calPi(int n){ double pi4=0.0; for(int i=0;i<=n;i++){ int m=2i+1; if(i%2==0){ pi4=pi4+1.0/m; }else{ pi4=pi4-1.0/m; } } return pi44; } public static String reverse(String s){ String r=""; for(int i=s.length()-1;i>=0;i--){ r=r+s.charAt(i); } return r; } public static String decToHex(int dec){ String hex=""; while(dec>=16){ int reminder=dec%16; dec=dec/16; if(reminder<10){ hex=hex+reminder; }else{ char ch=(char)('A'+(reminder-10)); hex=hex+ch; } } if(dec!=0){ hex=hex+dec; } return reverse(hex); } public static void main(String[] args){ int m=countNum(1234); System.out.printf("%d%n",m); int ret=factorial(5); System.out.printf("%d%n",ret); int a=addFactorial(3); System.out.printf("%d%n",a); double b=plusOrMinusAdd(5); System.out.printf("%f%n",b); double c=calPi(50); System.out.printf("%f%n",c); System.out.println(reverse("message")); System.out.println(decToHex(21954)); } }