1.

wap in java to print the sum of the given series- S= 1+3+7+13+...n terms

Answer»

import java.util.Scanner;
public class Print_Series2 {

    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int n,i,pr=0;
       System.out.printf("Enter the range of number(Limit):");
        n=sc.nextInt();
        for(i=1;i<=n;i++)
        {
            pr=(pr*2)+1;
            System.out.print(pr+" ");
        }
        sc.close();
    }
}



Discussion

No Comment Found

Related InterviewSolutions