24 lines
575 B
Java
24 lines
575 B
Java
public class GeneralizedHarmonic
|
|
{
|
|
public static void main(String[] args)
|
|
{
|
|
int n = Integer.parseInt(args[0]);
|
|
int r = Integer.parseInt(args[1]);
|
|
if (r >= 0 && n >= 0)
|
|
{
|
|
double h = 0;
|
|
double breuk = 0;
|
|
for (int i = 1; i <= n; i++ )
|
|
{
|
|
breuk = 1/(Math.pow(i,r));
|
|
h += breuk;
|
|
}
|
|
System.out.println(h);
|
|
}
|
|
else
|
|
{
|
|
System.out.println("Negative number in one of the arguments");
|
|
}
|
|
}
|
|
}
|