Here you can find the source of sum(double start, double end, double step)
public static double sum(double start, double end, double step)
//package com.java2s; /** This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. *///w ww. j a v a 2 s.c o m public class Main { public static double sum(double start, double end, double step) { if (start > end) { throw new IllegalArgumentException("Lower limit > upper limit!"); } else if (start + step > end) { throw new IllegalArgumentException("Lower limit + step > upper limit!"); } else if (step <= 0) { throw new IllegalArgumentException("Step = 0!"); } else if (start == end) { return start; } else { double sum = 0; for (double i = start; i <= end; i += step) { sum += i; } return sum; } } }