EDIT - This was originally two threads that have been merged.
Hello, I need help with using recursion in a Java program! My assignment is to:
Write a program to compute the harmonic sum using a recursive harmonicSum() function. HarmonicSum = 1 + 1/2 + 1/3 + …. 1/n
Here is what I have so far:
class Harmonic
{
public harmonicSum(int n)
{
if (n == 1) return 1;
return n * fractor(n-1);
}
}
public static void main(String[] args)
{
Harmonic factor = new Harmonic();
factor.harmonicSum(int n)
}
-I do not completely understand all of this yet, so any input is appreciated. Also am I going to need some kind of loop?
Hello, I need help with using recursion in a Java program! My assignment is to:
Write a program to compute the harmonic sum using a recursive harmonicSum() function. HarmonicSum = 1 + 1/2 + 1/3 + …. 1/n
Here is what I have so far:
class Harmonic
{
public harmonicSum(int n)
{
if (n == 1) return 1;
return n * fractor(n-1);
}
}
public static void main(String[] args)
{
Harmonic factor = new Harmonic();
factor.harmonicSum(int n)
}
-I do not completely understand all of this yet, so any input is appreciated. Also am I going to need some kind of loop?