展开全部
public class Slum {
public static void main(String[] args) {
//1,3,3
//等差数列:1,2,3... 前3项求和如下:
System.out.println("Sn = "+a1suman(1,3,3));
System.out.println("Sn = "+sumnda(3,1,1));
System.out.println("Sn = "+sumnda2(1,3,1));
}
//知道a1,an
public static int a1suman(int a1, int an, int n){
return (a1+an)*n/2;
}
//知道n,d,a1
public static int sumnda(int n, int a1, int d){
return n*a1+n*(n-1)*d/2;
}
//知道n,d,a1
public static int sumnda2(int a1, int n, int d){
return (2*a1+(n-1)*d)*n/2;
}
}
展开全部
public class Sequence {
int n0;//first term
int sum;//sum of the Sequence
int d;//tolerance
public Sequence( int n0,int d){
this.n0=n0;
this.d=d;
}
public static int SUM(int n0,int n,int d) {//return sum of n terms
int sum=n*n0+n*(n-1)*d/2;
return sum;
}
public static void main(String args[]){
Sequence s1=new Sequence(5,8);
System.out.print(SUM(5,20,8));
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询