Created
February 9, 2015 02:26
-
-
Save dmnugent80/5b6142686178d8adf893 to your computer and use it in GitHub Desktop.
Square of Sums and Sum of Squares
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class DifferenceOfSquares | |
{ | |
public static void main(String[] args) | |
{ | |
long sumOfSquares = 0; | |
long squareOfSums = 0; | |
long difference = 0; | |
for (long i = 1; i <= 100; i++){ | |
sumOfSquares += i * i; | |
squareOfSums += i; | |
} | |
squareOfSums = squareOfSums * squareOfSums; | |
difference = squareOfSums - sumOfSquares; | |
System.out.print("difference is: " + difference ); | |
} | |
} | |
/*output: | |
difference is: 25164150 | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment