954,536 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Whats wrong with this code?

Howdy, Im getting the "'.class expected" error and I dont know what to correct. The code is

import java.io.*;
public class TeamHeight
{
public static void main (String[] args)
   	throws IOException
	{
       	double[] height = new double[11];
		double sum = 0;
		System.out.println ("The size of the array: " + height.length);
		for (int i = 0; i < height.length; i++)
       	 	{
           
BufferedReader keyIn = new BufferedReader (new InputStreamReader(System.in));
        			System.out.print ("Enter the height of the player: ");
        			height = Double.parsedouble[](keyIn.readLine());
System.out.print ("Player " + (i+1) + ": ");
			height[i] = Integer.parseInt(keyIn.readLine());
			sum = sum + height[i];       
		 	}
		System.out.println ("The average height: " + (sum/11));
		System.out.println ();
	}
}


Thanks
-Airman

AirmanTheGreat
Light Poster
25 posts since Aug 2008
Reputation Points: 10
Solved Threads: 0
 

Have you compiled the code? That error usually relates to attempting to run a main method in a file that has not yet been compiled. If that was a compiler error, which line(s) give the error?

darkagn
Veteran Poster
1,197 posts since Aug 2007
Reputation Points: 404
Solved Threads: 200
 
Have you compiled the code? That error usually relates to attempting to run a main method in a file that has not yet been compiled. If that was a compiler error, which line(s) give the error?

Nope the code is not compiled. This error occurs when i attempt to compile it.

The error is at the line:


BufferedReader keyIn = new BufferedReader (new InputStreamReader(System.in));
System.out.print ("Enter the height of the player: ");height = Double.parsedouble[](keyIn.readLine());

AirmanTheGreat
Light Poster
25 posts since Aug 2008
Reputation Points: 10
Solved Threads: 0
 

You should read a value, parse it put in your array and then start over. You cannot have parsedouble[] (actually the correct version is parseDouble(args)). When you read a value, you cannot convert it to an array. Just put it to the next location in your array.

Chaster
Junior Poster in Training
68 posts since Jun 2007
Reputation Points: 12
Solved Threads: 3
 

I mean:

double temp = Double.parseDouble(keyIn.readLine());


an then:

height[i] = temp;
Chaster
Junior Poster in Training
68 posts since Jun 2007
Reputation Points: 12
Solved Threads: 3
 

I changed the parse thing to

height = Double.parseDouble(KeyIn.readLine());

and now I get the error:

Incompatible types - found Double but expected Double[]

AirmanTheGreat
Light Poster
25 posts since Aug 2008
Reputation Points: 10
Solved Threads: 0
 

I changed the parse thing to

height = Double.parseDouble(KeyIn.readLine());

and now I get the error:

Incompatible types - found Double but expected Double[]

That's because height is an ARRAY but you here need a PRIMITIVE. You can use either a temp variable (as I described earlier), or try this: height[i] = Double.parseDouble(...);

Chaster
Junior Poster in Training
68 posts since Jun 2007
Reputation Points: 12
Solved Threads: 3
 

Thanks, Chaster!
Solved :)

AirmanTheGreat
Light Poster
25 posts since Aug 2008
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You