Java Series Programs

Write a program in Java to find the sum of the given series:

S = (a*2) + (a*3) + …… + (a*20)

Java

Java Iterative Stmts

13 Likes

Answer

import java.util.Scanner;

public class KboatSeries
{
    public static void main(String args[]) {
        Scanner in = new Scanner(System.in);
        System.out.print("Enter a: ");
        int a = in.nextInt();
        long sum = 0;
        for (int i = 2; i <= 20; i++)
            sum += a * i;
        System.out.println("Sum = " + sum);
    }
}

Variable Description Table

Program Explanation

Output

Answered By

6 Likes