Untitled
unknown
plain_text
8 months ago
576 B
3
Indexable
Never
import java.util.Scanner; public class HarmonicSeriesSum { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); // Input value of n System.out.print("Enter the value of n: "); int n = scanner.nextInt(); // Calculate the sum of the harmonic series double sum = 0.0; for (int i = 1; i <= n; i++) { sum += 1.0 / i; } // Display the sum System.out.println("Sum of the harmonic series up to " + n + " terms: " + sum); scanner.close(); } }
Leave a Comment