物件導向程式設計

 

 

      2.7 Double數運算

 

 


授課教師:陳慶瀚

WWW : http://www.miat.ee.isu.edu.tw/java

E-mail : pierre@isu.edu.tw   

 


class AddDoubles 
{
  public static void main (String args[]) 
  {
    double x = 7.5;
    double y = 5.4; 
    double z;
    System.out.println("x is " + x);
    System.out.println("y is " + y);
  
    z = x + y;
    System.out.println("x + y is " + z);
    
    z = x - y;
    System.out.println("x - y is " + z);
  }
} 
 

Here's the result:

C:\> javac AddDoubles.java
C:\> java AddDoubles
x is 7.5
y is 5.4
x + y is 12.9
x - y is 2.0999999999999996
C:\>
 

 

物件導向程式設計

義守大學電機系 陳慶瀚

2001.10.02