问题 6,问题,public class
分享于 点击 13734 次 点评:45
问题 6,问题,public class
public class Prob6{ public static void main(String[] argsv){ int start = new Integer(argsv[0]).intValue(); int end = new Integer(argsv[1]).intValue(); System.out.println(difference(start, end)); } private static long difference(int start, int end){ return squareOfSum(start, end) - sumOfSquares(start, end); } private static long squareOfSum(int start, int end){ long result = 0; while(start <= end){ result += start; start++; } return result * result; } // Interval [start, end] private static long sumOfSquares(int start, int end){ long result = 0; while(start <= end){ result += start * start; start++; } return result; } }
用户点评