act an assignment because that my computer system science class and can"t quite figure out what I"m law wrong. I need to write a regime that adds every the squares between 1 and also 100 (1, 4, 9, 16, 25, 36, 49, 64, 81, 100) As part of the assignment I"m forced to use a "while" statement, so no "for" statements will help. My current code is together follows.

import java.util.Scanner;public course While42B { public revolution void main(String <>args ) { Scanner leader = new Scanner(System.in); int n = 1; int sum = 0; while (n and the return I obtain from the GUI is

710

Any help would be significantly appreciated, say thanks to you!

You are watching: The sum of all squares between 1 and 100  Look in ~ this statement:

n = (n*n);You"re squaring n within the loop, and then incrementing it. Perform the complying with instead:

while (n This way, girlfriend don"t modify n through squaring it, and you have the right to properly monitor its value for the when loop. I realize you"re looking for a while loop butjust FYI you have the right to use the straight formula:

System.out.println( n * (n + 1) * (2 * n + 1) / 6); Just as an add-on, in Java 8, one have the right to do the amount of squares of first 10 herbal numbers as follows:

int amount = IntStream.rangeClosed(1, 10).map(n -> n * n).sum(); If you desire to perform it in your method I mean an initial square the value of each number,keep that in a variable and include it come the amount you have the right to use a different variable rather of n to save the square worth of each number like this :

int n = 1;int squareValue;int amount = 0;while (n
You are an altering the value of n in: n= n*nSo now you space not looping from 1 to 100, you space skipping a many numbers

See more: Black Guys In Underwear In All, I Love Black Guys Underwear & Panties

Simply review the mathematics and also then continue to translate the mathematical operations right into code.I"ve cleared up the mathematics which i hope could aid you. I have actually also provided an answer to the question stated by her professor, I execute hope that ns am may be to have actually been useful in your arrangements. No credit transaction needed except to Carl Friedrich Gauss.

X(nsquared base 1 + nsquared base n) separated by 2

X equals variety of numbers (100) and also n basic 1 equals first number (1) and also n base n equates to last number (100), ns did not encompass the squares in the number description yet you do require too encompass squares in the an initial and last number. 1 squared and also 100 squared.

Do these operations according also PEMDAS ( bespeak of work ).I don"t have actually a high enough reputation so i can"t write-up photos, sorry because that that, ns hope this all helped though.The answer is (500,050)