/* * newStd.java */ public class newStd { public static void main (String args[]) { // declaring a constant variable final int NUM = 7; int number = 0; double total = 0; int counter = 0; double average; double values[] = new double[7]; int times[] = new int[7]; boolean done = false; double term,sum=0; double std; while (!done) { /* uses method from Console class to read formatted input - prints the argument as a prompt, then reads an int terminated by a newline */ values[counter] = Console.readDouble("Value: "); times[counter] = Console.readInt(" times: "); total += values[counter] * times[counter]; number += times[counter]; if (values[counter]==0) done = true; counter ++; } // cast to get floating point arithmetic average = (double)total / number; for (int i=0; i < counter; i++) { term = (average - values[i]); sum = sum + term * term * times[i]; } std = Math.sqrt(sum / number); System.out.println ("The mean of these numbers is " + average ); System.out.println ("The std of these numbers is " + std); } }