| | |
Whats wrong with this code?
Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
![]() |
Howdy, Im getting the "'.class expected" error and I dont know what to correct. The code is
Thanks
-Airman
Java Syntax (Toggle Plain Text)
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
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?
There are no stupid questions, only those too stupid to ask for help.
echo is a web developer's best friend. •
•
•
•
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?
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());
•
•
Join Date: Jun 2007
Posts: 59
Reputation:
Solved Threads: 3
I mean:
an then:
Java Syntax (Toggle Plain Text)
double temp = Double.parseDouble(keyIn.readLine());
an then:
Java Syntax (Toggle Plain Text)
height[i] = temp;
Last edited by Chaster; Aug 14th, 2008 at 6:27 am.
•
•
Join Date: Jun 2007
Posts: 59
Reputation:
Solved Threads: 3
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.
![]() |
Similar Threads
- Please help me i dont understand whats wrong with my code (C++)
- Please help me figure out whats wrong with my code (C++)
- whats wrong with my code cant display result (C)
- Whats wrong with this class??? (C++)
- Whats wrong with this code (PHP)
- Hello Everyone, I need Help with my C++ Code... (C++)
Other Threads in the Java Forum
- Previous Thread: Please help Errors will not compile
- Next Thread: Adding images to JAR file (Netbean 5.0)
| Thread Tools | Search this Thread |
Tag cloud for Java
affinetransform android api apple applet application arc arguments array arrays automation binary bluetooth businessintelligence chat class classes client code component database desktop draw ebook eclipse equation error event exception fractal game givemetehcodez graphics gui html ide image input integer intellij intersect iphone j2me java javaexcel javaprojects jmf jni jpanel julia linked linux list loop loops mac main map method methods mobile netbeans newbie number online open-source oracle parameter print problem program programming project properties recursion reference replaysolutions reporting rotatetext scanner screen scrollbar server set size sms socket sort sql string superclass swing template test threads time tree windows working xstream





