I am writing a program that reads unspecified number of integers from a user. It tells the number of positive and negative integers, computes the sum and average of all the integers entered. When user enters 0, that's the end of input. Someone should help me out
Asked
Active
Viewed 117 times
-2
-
Take a look at example 4 from duplicate (you may need to refresh this page to see link to duplicate question - it should be placed at top of your question). – Pshemo Aug 06 '16 at 14:21
1 Answers
0
If you want the exit your read operation when user enter 0,
Sample code
while(sc.hasNext()) {
int no = sc. nextInt();
if(no == 0) { // when zero is there break loop
break;
}
//operate
}
![](../../users/profiles/3187349.webp)
Maheshwar Ligade
- 6,171
- 3
- 35
- 53