Here you can find the source of sumFromNtoM(int n, int m)
public static int sumFromNtoM(int n, int m)
//package com.java2s; //License from project: Open Source License public class Main { /**/* w w w . j a va2 s . co m*/ * Returns the sum from n to m (Ex: n = 1, m = 3 => 1 + 2 + 3 = 6) */ public static int sumFromNtoM(int n, int m) { return Math.abs(m - n + 1) * (m + n) / 2; } }