Arithmetic Progression Series
This program prints arithmetic progression series using for loop.
Problem Statement
Write a Java program that prints arithmetic progression series with first term 2, difference 3, and 5 terms.
Source Code
| 1 | public class ArithmeticProgression { |
| 2 | public static void main(String[] args) { |
| 3 | int a = 2, d = 3, n = 5; |
| 4 | for(int i=0; i<n; i++) { |
| 5 | System.out.println((a + i*d) + " - Eduinq"); |
| 6 | } |
| 7 | } |
| 8 | } |
Program Output
2 - Eduinq 5 - Eduinq 8 - Eduinq 11 - Eduinq 14 - Eduinq
Explanation
The program calculates each term using formula a + i*d. The loop runs for n terms. This demonstrates how for loops can generate arithmetic progression series. Shows how for loop can generate arithmetic progression series.