Combine the statements that you wrote into a Java application that calcu- lates and prints the sum of the integers from 1 to 10. Use a while statement to loop through the calculation and increment statements. The loop should terminate when the value of x becomes 11.

What will be an ideal response?


```
// Exercise 4.6: Calculate.java
// Calculate the sum of the integers from 1 to 10
public class Calculate {
public static void main(String[] args) {
int sum = 0;
int x = 1;

while (x <= 10) { // while x is less than or equal to 10
sum += x; // add x to sum
++x; // increment x
}

System.out.printf("The sum is: %d%n", sum);
}
}

```
The sum is: 55

Computer Science & Information Technology

You might also like to view...

A flowchart is a visual plan for your presentation that helps you determine the direction of your presentation

Indicate whether the statement is true or false

Computer Science & Information Technology

When installing RAM modules, remember to protect the chips against dynamic electricity.

a. true b. false

Computer Science & Information Technology

Visual Basic contains a code library of almost ____ pieces of code called code snippets.

A. 125 B. 250 C. 500 D. 750

Computer Science & Information Technology

A(n) ____ probe uses existing access points to monitor the RF.

A. superposed B. overlay C. integrated D. external

Computer Science & Information Technology