Write a program to add of doubles in java?
Doubles are treated much the similar way, but now you obtain to use decimal points in the numbers. This is a same program which does addition and subtraction on doubles.
class AddDoubles {
public static void main (String args[]) {
double x = 7.5;
double y = 5.4;
System.out.println("x is " + x);
System.out.println("y is " + y);
double z = x + y;
System.out.println("x + y is " + z);
z = x - y;
System.out.println("x - y is " + z);
}
}
Here's the result:
% javac AddDoubles.java
% java AddDoubles
x is 7.5
y is 5.4
x + y is 12.9
x - y is 2.0999999999999996