Arithmetic Progression Series with While Loop
This program prints arithmetic progression series using while loop.
Problem Statement
Write a Java program that prints AP series with first term 5, difference 2, and 6 terms using while loop.
Source Code
| 1 | public class APWhile { |
| 2 | public static void main(String[] args) { |
| 3 | int a = 5, d = 2, n = 6, i = 0; |
| 4 | while(i < n) { |
| 5 | System.out.println((a + i*d) + " - Eduinq"); |
| 6 | i++; |
| 7 | } |
| 8 | } |
| 9 | } |
Program Output
5 - Eduinq 7 - Eduinq 9 - Eduinq 11 - Eduinq 13 - Eduinq 15 - Eduinq
Explanation
The program uses while loop to generate AP terms. Each iteration prints a + i*d. Shows how while loop can generate AP series.