Computer Science, asked by ansty, 5 months ago

Display the first 10 terms5, 10, 15, .........

Answers

Answered by anindyaadhikari13
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.

  1. public class Series {
  2. public static void main(String[] args) {
  3. for(int i=1, a=5;i<=10;i++, a+=5)
  4. System.out.print(a+" ");
  5. }
  6. }

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