write a Java program to print following series
Attachments:
Answers
Answered by
0
Answer:
Yes,I got it
Explanation:
import java.util.Scanner;
public class loveuNitish
{
public static void main(String args[]) {
Scanner in = new Scanner(System.in);
int sum = 0;
System.out.print("Enter the value of n ");
int n = in.nextInt();
for (int i = 1; i <= n; i++) {
int term = (int)Math.pow(2, i);
if (i % 2 == 0)
sum -= term;
else
sum += term;
}
System.out.println("Sum=" + sum);
}
}
Similar questions