Java write a program to calculate the sum of each of the ser
来源:学生作业帮 编辑:神马作文网作业帮 分类:综合作业 时间:2024/11/12 02:26:28
Java write a program to calculate the sum of each of the series:(a)1+4+9+16+...to 20terms.
import java.util.Scanner;
public class Sum {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
// 创建一个输入容器
Scanner input = new Scanner(System.in);
System.out.println("输入一个开始数:");
int start = input.nextInt();
System.out.println("输入想计算的个数:");
int end = input.nextInt();
Sum s = new Sum();
int sum = s.sum(start,end);
System.out.println("答案是:" + sum);
}
public int sum(int start,int end) {
int sum = 0;
int sum2 = 0;
for (int i = 0; i < end; i++) {
sum = sum + 1 + 2 * i;
sum2+=sum;
}
return sum2;
}
}
public class Sum {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
// 创建一个输入容器
Scanner input = new Scanner(System.in);
System.out.println("输入一个开始数:");
int start = input.nextInt();
System.out.println("输入想计算的个数:");
int end = input.nextInt();
Sum s = new Sum();
int sum = s.sum(start,end);
System.out.println("答案是:" + sum);
}
public int sum(int start,int end) {
int sum = 0;
int sum2 = 0;
for (int i = 0; i < end; i++) {
sum = sum + 1 + 2 * i;
sum2+=sum;
}
return sum2;
}
}
Java write a program to calculate the sum of each of the ser
Java write a program to calculate the factorial of any natur
Calculate the pH of each of the following solutions.
C语言的简易编程问题Your task is to Calculate the sum of some integers
Write a program which allows the user to enter a list of num
Write a program which allows the user to input a list of fiv
Write a program to append one file”1.txt” at the end of anot
acm Calculate the Sum
A great number of factors contribute to the increasingly ser
Please write a Java program,compute the GreatestCommonDiviso
Write a program,which performs as the following:(java)
Java write a program to read an integer,n,from the keyboard