Display the first 10 terms5, 10, 15, .........
Answers
Answered by
2
Required Answer:-
Question:
- Write a program in Java to display the first 10 terms of the series 5, 10, 15,...
Solution:
Here is the code.
- public class Series {
- public static void main(String[] args) {
- for(int i=1, a=5;i<=10;i++, a+=5)
- System.out.print(a+" ");
- }
- }
Explanation:
- Series questions are solved using looping construct. In this program, a loop is created that iterates 10 times. You can see that value of a is 5 initially. After each iteration, it will display the value of a and it's value will be increased by 5. In this way, the program works.
Output is attached for verification.
Attachments:
Similar questions