Java Program on Sum of Harmonic Series
- Categories Java
Write a program to sum of Harmonic Series 1 + 1/2 + 1/3 + 1/4 + 1/5
import java.util.Scanner; public class HarmonicSeries { public static void main(String args[]) { int num ; Scanner sc = new Scanner( System.in ); System.out.print("Input a number: "); num = sc.nextInt(); double result = 0.0; while(num > 0){ result = result + (double) 1 / num; num--; } System.out.println("Output of Harmonic Series is "+result); } }
You may also like
Single Linked List Programs in Java
28 August, 2021
Implementing Stack using Array in Java
28 August, 2021
Constructor Programs
3 July, 2021