日期:2014-05-20 浏览次数:20688 次
public class TestTemp { public static void main(String[] args) { double[] f = new double[20]; f[0] = 2; f[1] = 3; double sum = 2/1 + 3.0/2; for(int i=2; i<20; i++) { f[i] = f[i-1]+f[i-2]; sum += ((double)f[i]/(i+1)); } System.out.println(sum); } }
------解决方案--------------------
第一题http://topic.csdn.net/u/20110530/15/7648f8f0-e2e2-4a5b-a35d-8a1bbb43ac09.html
------解决方案--------------------
第2题,写了个组合的方法,LZ自己再写个字符串全排列输出就可以了:
public static void main(String[] args) { String[] ssss = {"a","b","c","d","e"}; mm1(ssss); } public static void mm1(String[] str) { for(int i = 1; i<=str.length;i++) { mm2(str,i,""); System.out.println(); } } public static void mm2(String[] str,int n,String st) { if(str.length<n) { return; } else if(n==1) { String[] strr = new String[str.length]; for(int i = 0; i<str.length;i++) { strr[i] = st+str[i]; System.out.print(strr[i]+" "); } } else { String st2 = st+str[0]; String[] str2 = new String[str.length-1]; for(int i = 1; i <str.length;i++) { str2[i-1] = str[i]; } mm2(str2,n-1,st2); mm2(str2,n,st); } }