Computer Science, asked by kartikeyrai5jan2007, 10 months ago

write a program in java to print the series S=(a/2)+(a/5)+(a/8)+(a/11).....+(a/20)​

Answers

Answered by Jagriti916
23

import java.util.*;

public class Program

{

public static void main(String[] args)

{

Scanner sc = new Scanner(System.in);

System.out.println("Enter the value for A ");

double input = sc.nextFloat();

double sum=0;

for(int i=2;i<=20;i+=3) // to divide by 2,5,8 so on that is why increase by 3 to i

{

sum+=input/i;

}

System.out.println(sum );

}

}

Answered by sourajoyd
1

Answer:

import java.util.Scanner;

public class KboatSeries

{

public void computeSeriesSum() {

Scanner in = new Scanner(System.in);

System.out.print("Enter a: ");

int a = in.nextInt();

double sum = 0;

for (int i = 2; i <= 20; i = i + 3) {

sum += a / (double)i;

}

System.out.println("Sum=" + sum);

}

}

Similar questions