Hey I have a problem with number representation. Code is working properly but result is 2.516415E7 number with is good result but I prefer normal representation like 25164150. Unfortunately I can't use long type because I used Math.pow in code( which works only in double type) It is possible? How can I do it in Java?
this is my code:
//Find the difference between the sum of the squares of the first one hundred natural numbers
//and the square of the sum.
public class Sum_square_difference {
public double Sum_of_the_squares() {
double sum = 0;
for (int i = 1; i <= 100; i++) {
double squares = 0;
squares = Math.pow(i, 2);
sum += squares;
}
return sum;
}
public double Sum_of_the_natural_numbers() {
double result = 0;
double sum = 0;
for (int i = 1; i <= 100; i++) {
sum += i;
}
result = Math.pow(sum, 2);
return result;
}
public static void main(String[] args) {
Sum_square_difference sqare = new Sum_square_difference();
System.out.println(sqare.Sum_of_the_squares());
System.out.println(sqare.Sum_of_the_natural_numbers());
System.out.println(sqare.Sum_of_the_natural_numbers() - sqare.Sum_of_the_squares());
}
}