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...

When you use a password in addition to a temporary code sent to your mobile phone in order to log in to your online bank account, you are using ____.

A. two-factor authentication B. a personal identification number C. biometric data D. data encryption

Computer Science & Information Technology

Microsoft's Office Presentation Service feature allows you to share your presentation ____ with anyone having an Internet connection.

A. uniquely B. immediately C. remotely D. secretly

Computer Science & Information Technology