求解啊,拜托大神了!!!
2个回答
展开全部
public static void main(String[] args) {
double n1 = 1,n2 = 1,sum = 0;
int m = 3,n = 5;
System.out.println("n1="+n1);
System.out.println("n2="+n2);
for (int i = m; i <= n; i++) {
n2 = n1 + n2;
n1 = n2 - n1;
if(i >= m && i <= n){
sum += n2;
}
System.out.println("n"+i+"="+n2);
}
System.out.println(m+"至"+n+"项的和="+sum);
}
//m需要>=3
double n1 = 1,n2 = 1,sum = 0;
int m = 3,n = 5;
System.out.println("n1="+n1);
System.out.println("n2="+n2);
for (int i = m; i <= n; i++) {
n2 = n1 + n2;
n1 = n2 - n1;
if(i >= m && i <= n){
sum += n2;
}
System.out.println("n"+i+"="+n2);
}
System.out.println(m+"至"+n+"项的和="+sum);
}
//m需要>=3
展开全部
public class te
{
public long getF(int m, int n) {
long sum = 0;
long[] arr = new long[100];
for (int i = 1; i < 100; i++) {
if (i == 1 || i == 2) {
arr[i] = 1;
System.out.print(arr[i] + ",");
} else {
arr[i] = arr[i - 2] + arr[i - 1];
System.out.print(arr[i] + ",");
}
if (i >= m && i <= n) {
sum += arr[i];
}
}
System.out.println();
return sum;
}
public static void main(String args[]) {
te t=new te();
System.out.println(t.getF(1,3)); //m到n之和
}
}
{
public long getF(int m, int n) {
long sum = 0;
long[] arr = new long[100];
for (int i = 1; i < 100; i++) {
if (i == 1 || i == 2) {
arr[i] = 1;
System.out.print(arr[i] + ",");
} else {
arr[i] = arr[i - 2] + arr[i - 1];
System.out.print(arr[i] + ",");
}
if (i >= m && i <= n) {
sum += arr[i];
}
}
System.out.println();
return sum;
}
public static void main(String args[]) {
te t=new te();
System.out.println(t.getF(1,3)); //m到n之和
}
}
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询