On each user input, do this:
if(numberOfInputs == 0)
{
min = n;
max = n;
sum = n;
numberOfInputs++
}
else
{
if(n < min)
min = n;
if(n > max)
max = n;
numberOfInputs++;
sum += n;
}
When the loop is over, print min, max, and sum/numberOfInputs.
for average
while loop
sum += n;
}
outside of your while loop do
avg = sum / c;
c is your counter
Right I have done the first part of the code check it out what I need now is this program to print out the: largest, smallest and average here is the code so far:
import java.util.*;
public class One{
public static void main(String []args){
Scanner in = new Scanner(System.in);
System.out.println("Enter as many integers as you like");
int n ;
while(true){
if(!in.hasNextInt())
{
System.out.println("Invalid input has been entered please enter a positive integer:");
in.next();
}
else
{
n=in.nextInt();
if(n==0 || n<0) break;
System.out.println();
{
System.out.println("Please enter 0 or a negative number to see the: largest, smallest and average");
}
}
}
}
}