Iteratively gets the square of the sum of the numbers [num : 1] - Java java.lang

Java examples for java.lang:Math Number

Description

Iteratively gets the square of the sum of the numbers [num : 1]

Demo Code


//package com.java2s;

public class Main {
    /**/*from  w ww .  j  av a 2 s .c  o  m*/
     * Iteratively gets the square of the sum of the numbers [num : 1]
     *
     * @param num Number to start at
     * @return The square of the sum
     */
    public static long squareOfSum(long num) {
        long sum = 0;
        for (long i = num; i > 0; i--) {
            sum += i;
        }
        return (sum * sum);
    }
}

Related Tutorials