int x = 5;          //an integer (whole number)
  int x = -8976;      
// another one
  double y = 234.557  
// a real number 

   double x, y;
   x = Double.parseDouble(number1.getText());
   y = Double.parseDouble(number2.getText());
   greeting.setText("Answer: " + (x + y));

How to add two doubles together

Java's primitive types for numbers include the int type (for whole numbers) and the double type for numbers with decimal places (real numbers).

To add two doubles together use the code shown on the left in the actionPerformed method of the AddTwo Class.

Be sure to spell correctly, double and Double are different!


 
Close this window to return to the previous page


Questions or problems related to this web site should be addressed to Richard Jones who asserts his right to be identified as the author and owner of these materials - unless otherwise indicated. Please feel free to use the material presented here and to create links to it for non-commercial purposes; an acknowledgement of the source is required by the Creative Commons licence. Use of materials from this site is conditional upon your having read the additional terms of use on the about page and the Creative Commons Licence. View privacy policy.

Creative Commons License
This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 2.5 License.

© 2001 - 2006 Richard Jones, PO BOX 246, Cambridge, New Zealand; This page was last modified on April 4, 2006