KnowledgeBoat Logo

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

ICSE

11 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);
    }
}

Output

BlueJ output of Write a program in Java to find the sum of the given series: S = (a*2) + (a*3) + …… + (a*20)

Answered By

5 Likes