Untitled
unknown
plain_text
a year ago
457 B
6
Indexable
import java.util.Scanner; public class HarmonicSeriesSum { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); System.out.print("Enter the value of n: "); int n = scanner.nextInt(); double sum = 0.0; for (int i = 1; i <= n; i++) { sum += 1.0 / i; } System.out.println("Sum of the harmonic series for n = " + n + " is: " + sum); } }
Editor is loading...
Leave a Comment