3
Reply

Standard deviation

Prime b

Prime b

Apr 22 2012 2:55 PM
3.1k
I need to calculate standard deviation , and I cant figure out how to do it =(
I have all kind of variables you need, average of all numbers , sum of all numbers.


        int sum=0;
        int average = 0;
        int highestNumber = 0;
        int lowestNumber = 0;
        final int  matchedNumber = 500;
        final int lessThan = 1000;
        boolean found = false;
        int countLessThan= 0;
        int countAverage = 0;
        
        int limit = 10000;
        int[] array = new int[limit];
        
        Random gen = new Random();
        
        for(int index=0; index < array.length; index++)
        {
            // random values generated
            array[index] = gen.nextInt(10001 - 1+ 1) + 1;
            // sum of all numbers in array
            sum += array[index];
            // average of all numbers
            average = sum / array.length;
            //Highest number
           if(array[index]> highestNumber)
           {
               highestNumber = array[index];
           }
           if(array[index] < lowestNumber)
           {
               lowestNumber = array[index];
           }
            
           if(matchedNumber == array[index])
           {
               found = true;
           }
           if(array[index]< lessThan)
           {
               countLessThan++;
           }
           if(array[index]<average)
           {
               countAverage++;
           }
                  
            
        }
        System.out.println("The sum of all numbers is "+sum);
        System.out.println("The average of all numbers is "+average);
        System.out.println("The highest number is "+highestNumber);
        System.out.println("The lowest number is "+lowestNumber);
        System.out.println("Is there a numer 500 in array? "+found);
        System.out.println("There are  "+countLessThan+" numbers less than 1000");
        System.out.println("There are "+countAverage+" numbers less than average"); 

Answers (3)