Computer Science, asked by AngshumanRoy, 1 year ago

define a class series as follows: member methods-

1) double sum(int n): which returns the sum of first n terms of the series.

Q. write a main method to input the number of terms and find and display the sum of the series?
: 1/2+3/4+5/6......

please show step by step? please it's urgent. please?. i will surely mark you brainlist. please?

it's java language ok


nitish8089: TWO QUESTION 1. YOU DON'T SPECIFY WHAT LANGUAGE WE COULD USE FOR CODING. 2. YOU DID NOT TELL ABOUT WHAT'S YOUR SERIES STRUCTURE IT'S 1+2+3+.......+N or 1^2+2^2+3^2+... N^2 so please edit your question
AngshumanRoy: ok
AngshumanRoy: please please answer my question please bro
AngshumanRoy: please
AngshumanRoy: it's urgent
AngshumanRoy: please

Answers

Answered by nitish8089
4

your \: code \: ......
import java.util.Scanner;
public class Program
{
public static double sum(int n) {
double sum1=0;
double i=1.0;
int x=0;
if(n>0){
do{
sum1+=(i/(i+1));
i+=2;
x++;
}while(x!=n);
return sum1;
}

else{
return -1;
}
}
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int a=sc.nextInt();
System.out.println ("sum of the series to the:"+a+" term "+Program.sum(a));
}
}
____________________________________
Similar questions