📄 exercise3_28.java
字号:
// Exercise3_28.java: Test cancellation errors
public class Exercise3_28 {
final static int N = 50000;
public static void main (String[] args) {
System.out.println("The result of the backward computation " + backward());
System.out.println("The result of the forward computation " + forward());
double difference = backward() - forward();
System.out.println("difference is " + difference);
}
public static double backward() {
double sum = 0.0;
for (int i = N; i >= 1; i--)
sum += 1.0 / (double)(i);
return sum;
}
static double forward() {
double sum = 0.0;
for (int i = 1; i <= N; i++)
sum += 1.0 / (double)(i);
return sum;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -