The completed program is given below.
import java.util.Scanner ;
public class HarmonicTester
{
public static void main ( String[] args )
{
Scanner scan = new Scanner(System.in);
System.out.print("How many Terms? ");
int limit = scan.nextInt();
int term=1 ;
double sum = 0.0;
while ( term <= limit )
{
sum += 1.0/term; // add the next term to sum
term++ ; // increment term
}
System.out.println("Sum of " + limit + " terms:" + sum );
}
}
With my 750 MHz AMD Athlon
computer it takes
22
seconds to run the program with the limit set at 1,000,000,000.
With my more recent 3.3 GHz Ryzen computer this takes 4 seconds.
Is your computer slower or faster than mine?