Write a program in Java to calculate the sum of following series where n is input by
Fantastic news! We've Found the answer you've been seeking!
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 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);
}
}
Related Book For
Income Tax Fundamentals 2013
ISBN: 9781285586618
31st Edition
Authors: Gerald E. Whittenburg, Martha Altus Buller, Steven L Gill
Posted Date: