Thursday, October 11, 2012

Java Exercise #19: Sentinel Value

This program is to take series of input from user as ints and then sum them up.

Exercise: Write a program that requests user to enter integers util the value entered is zero (which is used as sentinel value). Sum all the integer values and display it.

Enter an int value (Progam exits if the value is 0): 5
Enter an int value (Progam exits if the value is 0): 3
Enter an int value (Progam exits if the value is 0): 2
Enter an int value (Progam exits if the value is 0): 1
Enter an int value (Progam exits if the value is 0): 0
The sum is 11


Download Code: Sentinel Value

No comments:

Post a Comment