Java examples for java.lang:Math Number
Recursively gets the sum of squares of numbers starting from num to 1
//package com.java2s; public class Main { /**// w ww.j a va 2 s.c o m * Recursively gets the sum of squares of numbers starting from num to 1 * * @param num Number to start at * @return The sum of the squares */ public static long sumOfSquares(long num) { if (num == 1 || num == 0) { return num; } else { return (num * num) + sumOfSquares(num - 1); } } }