Question: Write a program in Java to calculate the sum of following series where n is input by user. 1 1/2 1/3 1/4 1/5 ............1/n This
Write a program in Java to calculate the sum of following series where n is input by user. 1 1/2 1/3 1/4 1/5 ............1/n
This is what I have but is not working in VS is there something I did wrong?
import java.util.Scanner;
public class Loop4
{
public static void main(String[] args)
{
Scanner console = new Scanner (System
.in);
int number;
double sum = 0;
System.out .print("Enter number of
terms of series: ");
number = console.nextInt ();
for(int 1 = 1; 1 <= number; i++)
{
sum += 1.0/i;
}
System.out.println("sum: " + sum);
}
}
Step by Step Solution
3.43 Rating (159 Votes )
There are 3 Steps involved in it
1 Final answer 1 Online Java Compiler 2 import javautilScanner 3 4 p... View full answer
Get step-by-step solutions from verified subject matter experts
