More NetBeans moments
This commit is contained in:
@@ -4,13 +4,53 @@
|
||||
*/
|
||||
package mp3_calebfontenot;
|
||||
|
||||
import java.util.Scanner;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author caleb
|
||||
*/
|
||||
public class Stats {
|
||||
public static void main(String[] args)
|
||||
{
|
||||
|
||||
|
||||
public static void main(String[] args) {
|
||||
// Create scanner
|
||||
Scanner input = new Scanner(System.in);
|
||||
// Define variables
|
||||
double mean = 0; //It's twice as mean
|
||||
double inputSum = 0, numberOfTimesRun = 0, inputPow = 0, deviation = 0;
|
||||
String userInput = "";
|
||||
|
||||
// Prompt for input
|
||||
do {
|
||||
System.out.println("Press Y/y to enter a series of numbers or Q/q to quit.");
|
||||
System.out.println("Current sum: " + inputSum);
|
||||
userInput = input.next();
|
||||
if (userInput.toLowerCase().equals("y")) {
|
||||
try {
|
||||
do {
|
||||
System.out.print("Please enter a series of numbers; Type '-1' to quit (no quotes, you doofus!): ");
|
||||
userInput = input.next();
|
||||
if (Double.parseDouble(userInput) != -1) {
|
||||
inputSum += Double.parseDouble(userInput);
|
||||
inputPow += Math.pow(Double.parseDouble(userInput), 2);
|
||||
numberOfTimesRun++; // counter to store number of times we've added to input sum
|
||||
}
|
||||
System.out.println("Current sum: " + inputSum);
|
||||
System.out.println("Input sum^2: " + inputPow);
|
||||
} while (Double.parseDouble(userInput) != -1);
|
||||
} catch (Exception e) {
|
||||
System.out.println("Invalid input!");
|
||||
}
|
||||
}
|
||||
// Calculate mean
|
||||
mean = inputSum / numberOfTimesRun;
|
||||
// Calculate deviation
|
||||
deviation = ((numberOfTimesRun - 1) / (inputPow - (Math.pow(inputSum, 2) / numberOfTimesRun)));
|
||||
|
||||
System.out.println();
|
||||
System.out.println("The mean is: " + mean);
|
||||
System.out.println("The deviation is: " + deviation);
|
||||
|
||||
} while (!(userInput.toLowerCase().equals("q")));
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user