Basic java but i am getting an error in netbeans 6.5

public class math {
     * @param args the command line arguments
    public static void main(String[] args) {
    int x = (int) Math.PI * 20.0;
    System.out.println(x);
found   : double
required: int
    int x = (int) Math.PI * 20.0;
1 error
BUILD FAILED (total time: 0 seconds)

aszxcv02 wrote:
i am doing a book example that the int is suppose to round pie to 3 and then multiple by 20 so the answer will be 60
i just copied straight out the book and i was suppose to get back 60.Use parentheses or - if it is exactly as you describe - multiply by 20 rather than 20.0.
The point is that when you take pi cast to an int (ie, truncated to 3) and multiply it by a double you will get a double result. The compiler complains when you try and assign this double to an int variable.
Edited by: pbrockway2 on Dec 27, 2008 2:00 PM
Slow ;(
But make sure you understand why it works. There is an order to things:
(a) Get the double Math.pi
(b) Truncate it to an int
(c) Multiply the int by the int value 20
What does int x = (int)(Math.PI * 20.0); do? Why?

Similar Messages

Maybe you are looking for

  • Workaround for function to_blob in Oracle 8i

    Hi all, this query run in Oracle 9i but not in oracle 8i: select to_lob(dbms_lob.substr(data,dbms_lob.getlength(data)-dbms_lob.instr(data,'3F3E')-1,dbms_lob.instr(data,'3F3E')+4)) as stream_data, filename as stream_name, substr(filename,instr(filenam

  • Admin server on MS window while Managed Server on Unix

              Hi,           Is it possible to run Weblogic Administrative server 7.0 SP1 on MS Windows Platform           while run the Managed (or Clustered) Server instances on several Unix box           such as HPUX or Solaris?           thanks       

  • Org.apache.axis2.AxisFault: The service cannot be found for the endpoint

    Hi Team, I'm getting following error while runnig WebServices [ERROR] The service cannot be found for the endpoint reference (EPR) /TestServices/services org.apache.axis2.AxisFault: The service cannot be found for the endpoint reference (EPR) /TestSe

  • Link externally edited files to the original, like Aperture does

    This is one thing I really like about Aperture - when you edit files externally, Aperture keeps track of them, and keeps them associated with the original.  That little bit of housekeeping is a very nice touch.

  • Problem: Extension Manager not working - have loaded EM 1.7 w DW8

    I have tried to load extensions. The message says: "Macromedia Extension Manager Can not up date a file The extension can not be installed." I have deleted both D8 and EM 1.7. I have downloaded the latest update to Dreamweaver 8: http://www.adobe.com