Created
October 14, 2019 11:18
-
-
Save ChrisLeNeve/907e906a690b4b8a2e61380afa2ebe3a to your computer and use it in GitHub Desktop.
Project Euler: problem 6
This file contains 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
class Scratch { | |
public static void main(String[] args) { | |
System.out.println(solution(10)); | |
} | |
private static int solution(int max) { | |
int sumOfSquares = 0, sum = 0; | |
for (int i = 1; i <= max; i++) { | |
sumOfSquares += (i * i); | |
sum += i; | |
} | |
// sum = max * (max + 1) / 2; | |
return (sum * sum) - sumOfSquares; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment