Computer Science, asked by arpanseal327, 9 months ago

write a program in java and display the sum of the following series s=1^2/a+3^2/a^2+5^2/a^3+......... to n


Answers

Answered by anindyaadhikari13
1

Question:-

Write a program in Java to find the sum of the series.

S=1³/a + 3²/a^2 + 5²/a^3+...

Program:-

import java.util.*;

class Sum

{

public static void main(String args[])

{

Scanner sc=new Scanner(System.in);

System.out.print("Enter the value of a: ");

int a=sc.nextInt();

double b=1;

double s=0;

if(a!=0)

{

for(int i=1;i<=n;i++)

{

s+=b/Math.pow(a, i);

b+=2;

}

System.out.println("Sum of the series is: "+s);

}

else

{

System.out.println("Invalid Input...Please try again later..");

System.exit(0);

}

}

}

Similar questions