Go-Programm
Code: Select all
package main
import (
"math"
"fmt"
"time"
)
func main() {
fmt.Printf("vvalue is %v", testFun(10, 16666611, 1000000000))
}
func fun(x float64) float64 {
return math.Pow(x, 2) - x
}
func testFun(first float64, second float64, times int) float64 {
var i = 0
var result float64 = 0
var dx float64
dx = (second - first) / float64(times)
for ; i < times; i++ {
result += fun(first + float64(i) * dx)
}
return result * dx
}
Code: Select all
public class Test {
public static void main(String[] args) {
Test test = new Test();
double re = test.testFun(10, 16666611, 1000000000);
System.out.println(re);
}
private double testFun(double first, double second, long times) {
int i = 0;
double result = 0;
double dx = (second - first) / times;
for (; i < times; i++) {
result += fun(first + i * dx);
}
return result * dx;
}
private double fun(double v) {
return Math.pow(v, 2) - v;
}
}