| | |
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)
Views: 649 | Replies: 7
| Thread Tools | Search this Thread |
Tag cloud for Java
6 android api apple applet application arc arguments array arrays automation binary bluetooth bold c++ chat class classes client code compare component coordinates database datagram doctype draw eclipse educational error event exception file fractal froglogic game givemetehcodez graphics gui guitesting helpwithhomework html ide ideas image ingres input integer internet intersect ip j2me java javaexcel javaprojects jmf jni jpanel jtextarea julia linux list loop map method methods mobile netbeans newbie nextline number object oracle print problem program programming project recursion recursive scanner screen sell server set size sms socket sort sql string swing test threads time transfer tree user websites windows





