Solutions for Class 10 ICSE Logix Kips Computer Applications with BlueJ Java | IT Developer <?php echo $page_title; ?>
IT Developer

Iterative Constructs in Java

Chapter 9

Iterative Constructs in Java

Class 10 - Logix Kips ICSE Computer Applications with BlueJ


Share with a Friend

Java Program: Sum of Geometric Progression


30(x). Write a program in Java to find the sum of the given series:

      1 * 2 * 4 * 8 * ..... * 220

public class SumGeometricSeries

{

    public static void main(String args[]) {

 

        double sum = 0;

       

        for (int i = 0; i <= 20; i++) {

            double term = Math.pow(2,i);

            sum += term;

        }

           

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

       

    }

}

Output

Sample Output
Sum = 2097151.0 

📝 Explanation

  1. First term = 1
  2. Each term = previous term × 2
  3. Stop when i exceeds 20
  4. Add each term to sum