If you want to do it in your way I mean first square the value of each number,keep it in a variable and add it to the sum you can use a different variable
instead of n
to store the square value of each number like this :
int n = 1; int squareValue; int sum = 0; while (n <= 10) { squareValue= (n*n); sum += squareValue; n++; } System.out.println(sum);
Related Posts:
- Problem with gif with transparent background
- Search for words with telephone numbers from 2-3-4 tree
- Difference between Inheritance and Composition
- What is the reason behind “non-static method cannot be referenced from a static context”? [duplicate]
- Java string to date conversion
- Creating a “logical exclusive or” operator in Java
- Cannot make a static reference to the non-static method fxn(int) from the type Two [duplicate]
- Round a double to 2 decimal places [duplicate]
- Int division: Why is the result of 1/3 == 0?
- Given final block not properly padded
- What is Parse/parsing?
- What is IllegalStateException?
- Long vs Integer, long vs int, what to use and when?
- Java Using Nodes with LinkedList
- When is the @JsonProperty property used and what is it used for?
- Why is there no SortedList in Java?
- javac not working in windows command prompt
- Java returns error “Cannot instantiate the type”
- How does a Breadth-First Search work when looking for Shortest Path?
- Java: using switch statement with enum under subclass
- Java way to check if a string is palindrome
- No String-argument constructor/factory method to deserialize from String value (”)
- Where can i get BigClip? [closed]
- What is the /= operator in Java?
- How to execute a https GET request from java
- How to use VisibleForTesting for pure JUnit tests
- What is the easiest/best/most correct way to iterate through the characters of a string in Java?
- How can I list the available Cipher algorithms?
- ADK vs JDK vs SDK difference?
- round up to 2 decimal places in java?
- com.sun.jdi.InvocationException occurred invoking method
- How can I check whether an array is null / empty?
- How to solve javax.net.ssl.SSLHandshakeException Error?
- org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name ‘demoRestController’
- What causes java.lang.IncompatibleClassChangeError?
- Add an object to an Array of a custom class
- Using NotNull Annotation in method argument
- How to implement infinity in Java?
- Java Does Not Equal (!=) Not Working?
- How to represent empty char in Java Character class
- Definition of a Java Container
- ‘Source code does not match the bytecode’ when debugging on a device
- Determining Day of the week using Zeller’s Congruence in Java
- IO Error: The Network Adapter could not establish the connection
- How to create a directory in Java?
- Converting from Integer, to BigInteger
- Get a resource using getResource()
- Java comparing generic types
- Simplest way to read JSON from a URL in Java
- “The public type <
> must be defined in its own file” error in Eclipse [duplicate] - How to calculate the intersection of two sets?
- method does not override method in its superclass
- Adding a timer to my program (javafx)
- How to resolve “Syntax error on token “else”” in Java?
- java.lang.IndexOutOfBoundsException: Index: 0, Size: 0 exception
- What does this expression language ${pageContext.request.contextPath} exactly do in JSP EL?
- Simulating Game of Craps in JAVA
- Creating random numbers with no duplicates
- How to create a popup window in javafx
- java – How to handle array:Exception in thread “main” java.lang.ArrayIndexOutOfBoundsException: 3
- How to print the data in byte array as characters?
- An established connection was aborted by the software in your host machine tomcat jackson
- Generate a random double in a range
- How to open a new tab using Selenium WebDriver in Java?
- Selenium Webdriver: Element Not Visible Exception
- Whitespace Matching Regex – Java
- Unreachable code in eclipse
- “Field can be converted to a local variable” message appearing when setting Android ActionBar colour
- Convert an integer to an array of digits
- Error: package or namespace load failed for ‘rJava’
- Difference between regex [A-z] and [a-zA-Z]
- How can I convert a char to CharSequence?
- Problems Generating A Math.random Number, Either 0 or 1
- Android Emulator: Unfortunately App has stopped
- Can we execute a java program without a main() method? [duplicate]
- How to really read text file from classpath in Java
- Java command not found on Linux
- How do I convert this for loop into a while loop?
- Java switch statement: Constant expression required, but it IS constant
- Resolving File paths – ‘File not found’ error in Eclipse
- Python-like list comprehension in Java
- Can an int be null in Java?
- What’s the difference between HashSet and Set?
- Netbeans – Error: Could not find or load main class
- Eclipse IDE – Error: Build path specifies execution environment Java SE 1.7
- Why int[] a = new int[1] instead of just int a?
- ArithmeticException: “Non-terminating decimal expansion; no exact representable decimal result”
- When to use a Map instead of a List in Java?
- How do I replace a character in a string in Java?
- What’s so special about 0x7f?
- Append a single character to a string or char array in java?
- Preventing a Java class from being instantiated and inherited
- Collision Detection between two images in Java
- What does .pack() do?
- String is immutable. What exactly is the meaning?
- How do I autoindent in Netbeans?
- What is an attribute in Java?
- MessageBodyWriter not found for media type=application/json
- Conversion from Long to Double in Java
- Failed to find Java VM