public class MyClass {
public static void main(String args[]) {
double s=1.0;
double e=20.0;
System.out.println("\ni m(i) ");
System.out.println("-------------------");
for (double i=s; i<=e;i++)
{
System.out.printf("%-10.0f", i);
System.out.printf("%7.4f\n", series(i));
}
}
public static double series(double n) {
double sum = 0;
for (double i =1; i<=n;i++) {
sum += i / (i + 1);
}
return sum;
}
}
Result
i m(i)
-------------------
1 0.5000
2 1.1667
3 1.9167
4 2.7167
5 3.5500
6 4.4071
7 5.2821
8 6.1710
9 7.0710
10 7.9801
11 8.8968
12 9.8199
13 10.7484
14 11.6818
15 12.6193
16 13.5604
17 14.5049
18 15.4523
19 16.4023
20 17.3546
public static void main(String args[]) {
double s=1.0;
double e=20.0;
System.out.println("\ni m(i) ");
System.out.println("-------------------");
for (double i=s; i<=e;i++)
{
System.out.printf("%-10.0f", i);
System.out.printf("%7.4f\n", series(i));
}
}
public static double series(double n) {
double sum = 0;
for (double i =1; i<=n;i++) {
sum += i / (i + 1);
}
return sum;
}
}
Result
i m(i)
-------------------
1 0.5000
2 1.1667
3 1.9167
4 2.7167
5 3.5500
6 4.4071
7 5.2821
8 6.1710
9 7.0710
10 7.9801
11 8.8968
12 9.8199
13 10.7484
14 11.6818
15 12.6193
16 13.5604
17 14.5049
18 15.4523
19 16.4023
20 17.3546
No comments:
Post a Comment