Write a program to find the sum of the series:
s= 1- a + a2
- a3+ ---------------+a10 in java
. write accurately I have to type
Answers
Answered by
1
import java.util.Scanner;
class Sum {
public static void main() {
Scanner in = new Scanner(System.in);
int calc = 0;
int num = in.nextInt();
for (int i=1 ; i <= 10 ; i++) {
if (i%2 == 0)
calc += num * i;
else
calc -= num * i;
}
System.out.print("Sum is "+calc);
}
}
Similar questions