Harmonic Progression Pyramid
This program prints harmonic progression values in pyramid form.
Problem Statement
Write a Java program that prints harmonic progression pyramid up to 4 rows.
Source Code
| 1 | public class HarmonicPyramid { |
| 2 | public static void main(String[] args) { |
| 3 | int num = 1; |
| 4 | for(int i=1; i<=4; i++) { |
| 5 | for(int j=1; j<=i; j++) { |
| 6 | System.out.print("1/" + num + " "); |
| 7 | num++; |
| 8 | } |
| 9 | System.out.println(); |
| 10 | } |
| 11 | } |
| 12 | } |
Program Output
1/1 1/2 1/3 1/4 1/5 1/6 1/7 1/8 1/9 1/10
Explanation
The outer loop controls rows, inner loop prints reciprocals sequentially. This demonstrates harmonic progression pyramids using nested loops. Shows how nested loops can generate harmonic progression pyramids.