please tell this answer class 9 icse.
Attachments:
Answers
Answered by
4
Required Answer:-
Question:
Write a Java program to display the sum of the series.
S = 1*2 + 2*3 + 3*4 + . . . . . + 19*20
Solution:
Here comes the program.
public class Sum {
public static void main(String[] args) {
int i=1, s=0;
for(i=1;i<=19;i++)
s+=i*(i+1);
System.out.println("Sum: "+s);
}
}
Algorithm:
- START.
- Declare S = 0
- Iterate a loop in the range i = 1 to 19.
- Add the value of i(i + 1) to the sum after each iteration.
- Display the sum.
- STOP.
Refer to the attachment for output ☑.
Attachments:
Similar questions