ICSE Computer Science Java Programs | IT Developer
IT Developer

Java Programs - Solved 2016 ICSE Computer Science Paper



Share with a Friend

Solved 2016 ICSE Computer Science Paper

Class 10 - ICSE Computer Science Solved Papers

Function Overloading - Sum of Series Program - ICSE 2016 Computer Science

Design a class to overload a function sumSeries() as follows:
(i) void sumSeries(int n, double x): with one integer argument and one double argument to find and display the sum of the series given below:
s = x / 1 – x / 2 + x / 3 – x / 4 + x / 5 … N terms.
(ii) void sumSeries(): to find and display the sum of the following series:
s = 1 + (1 × 2) + (1 × 2 × 3) + … + (1 × 2 × 3 × 4 … × 20)

class Overload{ public static void sumSeries(int n, double x){ double s = 0.0; for(int i = 1; i <= n; i++) s += x / i; System.out.println("Sum = " + s); } public static void sumSeries(){ long s = 0L; long f = 1L; for(int i = 1; i <= 20; i++){ f *= i; s += f; } System.out.println("Sum = " + s); } }

Output