Results 1 to 4 of 4
  1. #1
    peterdfl is offline Member
    Join Date
    Mar 2008
    Posts
    8
    Rep Power
    0

    Unhappy standard deviation and mean for an array

    hey everyone, i just started doing arrays and the program i'm trying to create is supose to take 8 random numbers from the user then calculates the standard deviation, and the mean and provide the standard scores, right now i'm have 6 errors because of the array. The error are are saying ; epected at the end of the method, but i did that and it doesn work. if you can help if would be greatly appreciated!!! :)
    here's my code do far
    PHP Code:
    import java.util.Scanner;
    public class Statistics
    {
    	public static void main(String[] args)
    	{
    
    		Scanner keyboard= new Scanner(System.in);
    		int Mean = 0;
    		double SD= 0.0;
    		int Count= 0;
    		System.out.print("How many numbers will you be entering? ");
    		int NumAmount = keyboard.nextInt();
    
    
    		System.out.println("Thank you. Please enter the " + NumAmount + " values below:");
    
    		GetNumbers(NumAmount);
    		int ListNum= GetNumbers(NumAmount);
    		double [] values = new double [NumAmount];
    
    		StanDev(values, NumAmount);
    		System.out.println("Statistics for the given numbers:");
    }
    
    	static int GetNumbers(int NumAmount)
    	{
    		for (int n =0; n<=NumAmount;n++)
    		{
    		int [] values = new int [NumAmount];
    		Scanner keyboard= new Scanner(System.in);
    		int numbers = keyboard.nextInt();
    		System.out.println(numbers);
    		values [n]=numbers;
    	}
    
    	static double StanDev(double values,int NumAmount)
    
    	{
    		for(int i = 0; i < NumAmount; i++)
    		{
    		sum += values[i];
    	    double mean = sum / NumAmount;
    	    double sq_diff_sum = 0;
    		}
    
    	   	for(int i = 0; i <NumAmount ; ++i)
    		{
    	       double diff = values[i] - mean;
           	sq_diff_sum += diff * diff;
    
    		}
    		double deviance= sq_diff_sum / n;
        	return sqrt(deviance);
    
    		}
    	}
    }

  2. #2
    sukatoa's Avatar
    sukatoa is offline Senior Member
    Join Date
    Jan 2008
    Location
    Cebu City, Philippines
    Posts
    556
    Rep Power
    7

    Default

    Please check those braces that were not paired....

    specially at GetNumbers() and StanDev() method....
    freedom exists in the world of ideas

  3. #3
    sukatoa's Avatar
    sukatoa is offline Senior Member
    Join Date
    Jan 2008
    Location
    Cebu City, Philippines
    Posts
    556
    Rep Power
    7

    Default

    Java doesn't allow also to compile a method inside a method.
    freedom exists in the world of ideas

  4. #4
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

Similar Threads

  1. Sun Java Platform, Standard Edition 6u6
    By Java Tip in forum Java Software
    Replies: 0
    Last Post: 04-26-2008, 08:26 PM
  2. Sun Java Platform, Standard Edition 6u3
    By JavaBean in forum Java Software
    Replies: 0
    Last Post: 10-04-2007, 09:10 PM
  3. Sun Java Platform, Standard Edition 6u2
    By JavaBean in forum Java Software
    Replies: 0
    Last Post: 07-08-2007, 05:45 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •