Hi my code should do this instruction below but am not getting it at all
The user can enter as many positive floating-point numbers on the console as desired. Zero (or a negative numbers) signals end of input (no more numbers can be entered). After input the program displays ? the smallest number entered (min) ? the largest number entered (max) ? the mean of all numbers entered (mean) Do NOT use arrays for this assignment, even if you know them.
Sample should look like this
enter numbers: 1 2 3 4 5 6 0 numbers entered: 6 minimum: 1.00 maximum:6.00 mean: 3.50
enter numbers: 0 no number entered.
public class LoopStatistics {
public static void main(String[] args) {
double max, min, sum=0, input, mean=0;
int counter = 0;
TextIO.putln("enter numbers:");
do
{
input = TextIO.getDouble();
min = input;
max = input;
counter++;
if (input > max)
max = input;
if ( input < min)
min = input;
sum = sum + input;
} while( input != 0);
mean = sum / counter;
TextIO.putf("numbers entered:%d
", counter);
TextIO.putf("minimum:%f
", min);
TextIO.putf("maximum:%f
", max);
TextIO.putf("mean:%f", mean);
}
}
See Question&Answers more detail:os