943,648 Members | Top Members by Rank

Ad:
  • Java Discussion Thread
  • Unsolved
  • Views: 852
  • Java RSS
Aug 14th, 2008
0

Whats wrong with this code?

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

Java Syntax (Toggle Plain Text)
  1. import java.io.*;
  2. public class TeamHeight
  3. {
  4. public static void main (String[] args)
  5. throws IOException
  6. {
  7. double[] height = new double[11];
  8. double sum = 0;
  9. System.out.println ("The size of the array: " + height.length);
  10. for (int i = 0; i < height.length; i++)
  11. {
  12.  
  13. BufferedReader keyIn = new BufferedReader (new InputStreamReader(System.in));
  14. System.out.print ("Enter the height of the player: ");
  15. height = Double.parsedouble[](keyIn.readLine());
  16. System.out.print ("Player " + (i+1) + ": ");
  17. height[i] = Integer.parseInt(keyIn.readLine());
  18. sum = sum + height[i];
  19. }
  20. System.out.println ("The average height: " + (sum/11));
  21. System.out.println ();
  22. }
  23. }

Thanks
-Airman
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
AirmanTheGreat is offline Offline
21 posts
since Aug 2008
Aug 14th, 2008
0

Re: Whats wrong with this code?

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?
Reputation Points: 395
Solved Threads: 192
Veteran Poster
darkagn is offline Offline
1,136 posts
since Aug 2007
Aug 14th, 2008
0

Re: Whats wrong with this code?

Click to Expand / Collapse  Quote originally posted by darkagn ...
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());
Reputation Points: 10
Solved Threads: 0
Newbie Poster
AirmanTheGreat is offline Offline
21 posts
since Aug 2008
Aug 14th, 2008
0

Re: Whats wrong with this code?

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.
Reputation Points: 12
Solved Threads: 3
Junior Poster in Training
Chaster is offline Offline
68 posts
since Jun 2007
Aug 14th, 2008
1

Re: Whats wrong with this code?

I mean:
Java Syntax (Toggle Plain Text)
  1. double temp = Double.parseDouble(keyIn.readLine());

an then:
Java Syntax (Toggle Plain Text)
  1. height[i] = temp;
Last edited by Chaster; Aug 14th, 2008 at 6:27 am.
Reputation Points: 12
Solved Threads: 3
Junior Poster in Training
Chaster is offline Offline
68 posts
since Jun 2007
Aug 14th, 2008
0

Re: Whats wrong with this code?

I changed the parse thing to

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

and now I get the error:

Incompatible types - found Double but expected Double[]
Reputation Points: 10
Solved Threads: 0
Newbie Poster
AirmanTheGreat is offline Offline
21 posts
since Aug 2008
Aug 14th, 2008
0

Re: Whats wrong with this code?

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(...);
Last edited by Chaster; Aug 14th, 2008 at 9:15 am.
Reputation Points: 12
Solved Threads: 3
Junior Poster in Training
Chaster is offline Offline
68 posts
since Jun 2007
Aug 15th, 2008
0

Re: Whats wrong with this code?

Thanks, Chaster!
Solved
Reputation Points: 10
Solved Threads: 0
Newbie Poster
AirmanTheGreat is offline Offline
21 posts
since Aug 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Java Forum Timeline: Please help Errors will not compile
Next Thread in Java Forum Timeline: Application files Classs file





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC