Project Euler is a "series of challenging mathematical/computer programming problems" that may be completed in any language. For your programming homework, you must complete problem 6 from Project Euler in Java. The problem reads as follows:
The sum of the squares of the first ten natural numbers is,
12 + 22 + … + 102 = 385
The square of the sum of the first ten natural numbers is,
(1 + 2 + … + 10)2 = 552 = 3025
Hence the difference between the sum of the squares of the first ten natural numbers and the square of the sum is:
3025 – 385 = 2640
Find the difference between the sum of the squares of the first one hundred natural numbers and the square of the sum.
Specifically, you must create a file ProjectEuler06.java that solves this problem by reading from the command-line the number of natural numbers to consider. For example, the following are two example runs of this program:
$ java ProjectEuler06 10
Considering the first 10 natural numbers.
The sum of squares is 385.0.
The square of the sum is 3025.0.
The difference is 2640.0.
$ java ProjectEuler06 12
Considering the first 12 natural numbers.
The sum of squares is 650.0.
The square of the sum is 6084.0.
The difference is 5434.0.
Note that the $ indicates the command-line prompt. The lines that do NOT start with $ are output by the Java program.
Hint: To complete this homework, you may need to use the Math.pow() method.
You must submit your code via SVN as follows:
https://www.cs.usfca.edu/svn/username/cs212/homework01/src/ProjectEuler06.java
Replace username with your USF Connect username.
Your code must be committed by 11:59pm on Friday, February 1, 2013. Late homework is not accepted.
WARNING: Your code may be used in class as an example. All personally identificable information will be removed. Your identity will not be revealed.