Write a code fragment that allows a user to continue inputting numbers until she enters a sentinel value of 0. Then print the sum of all the numbers she entered. You may assume that a Scanner object named input has already been created.

What will be an ideal response?

```
int sum = 0;
int inputInt;
do {
System.out.print("Please enter an integer (0 to quit): ");
inputInt = input.nextInt();
sum += inputInt;
}while(inputInt != 0);
System.out.println("The sum of the numbers is " + sum);
```

Computer Science & Information Technology

You might also like to view...

A collection of related data about a particular topic or purpose is called a(n) ________

Fill in the blank(s) with correct word

Computer Science & Information Technology

Which Cisco IOS command is used to display the IPv6 neighbors that have been discovered via the ND protocol?

A) show nd neighbors B) show ipv6 nd neighbors C) show ipv6 neighbors D) show nd ipv6 neighbors

Computer Science & Information Technology