Finding the average of random numbers a user inputs
Here's my code. How do I get the output average when the user enters the random numbers. I keep getting 0.0 for the average.
Package averages;
import java.util.Scanner;
/**
*
* @author Kramer1
*/
Public class Averages {
/**
* @param args the command line arguments
*/
Public static void main(String[] args) {
// TODO code application logic here
Scanner in = new Scanner(System.in);
Double sum = 0;
int count = 0;
Double input = 0;
System.out.println("Enter in as many numbers as you want and the average will be calculated: ");
Do{
System.out.print ("Please enter a number and when finished type a -1 to stop: ");
input = in.nextDouble();
}
While (input != -1);
Count++;
if (input != -1){
Sum = (input + sum);
Double average = sum / count;
System.out.println("Average of the numbers is " + average);
}else{
System.out.println("No Data.");
}
}
}