C:\Users\ar114\Documents\NetBeansProjects\Exam2_CalebFontenot\src\exam2_calebfontenot\Problem1.java |
package exam2_calebfontenot;
import java.util.Scanner;
@author
public class Problem1 {
@param args
public static void main(String[] args) {
double userInput = 0, average = 0;
int timesRun = 0;
Scanner input = new Scanner(System.in);
System.out.println("I will calculate the average of numbers you will enter. \n");
while (userInput != -1) {
System.out.print("Enter a positive number, or type -1 to quit: ");
userInput = input.nextDouble();
if (userInput != -1) {
average += userInput;
timesRun++;
}
}
average = average / (double) timesRun;
System.out.println("The average is: " + average);
}
}