Category : Java | Sub Category : Operator | By Prasad Bonam Last updated: 2020-09-28 13:15:38 Viewed : 460
(Operator)
Write a program which demonstrate the arithmetic operator
Source Code: BasicMath.java
/**
* Write a program which demonstrate
the arithmetic operator
*
*/
class BasicMath { // This line daclare a
new class & the class defination is start.
public static void
main(String a[]) { // This line begins the main() method.
System.out.println("Integer
Arithmetic"); // arthmetic using integers
int
x = 1 + 1; // store 2 in variable x
int
b = x * 3; // x multiply a by 3 and store in b.
int
c = b / 4; // b divide b by 4 and store in c.
int
d = c - x; // c minus x and store in d
int
e = -d; // minus of d is
System.out.println("a
= " + x); // print value of a
System.out.println("b
= " + b); // print value of b
System.out.println("c
= " + c); // print value of c
System.out.println("d
= " + d); // print value of d
System.out.println("e = "
+ e); // print value of e
System.out.println("
Floating
Point Arithmetic"); // Arthmetic using doubles
double
da = 1 + 1; // store 2 in variable da
double
db = da * 3; // multiply da by 3 and store in db.
double
dc = db / 4; // divide db by 4 and store in dc.
double
dd = dc - da; // value of dc minus da store in dd
double
de = -dd; // value of dd store in de
System.out.println("da
= " + da); // print value of da
System.out.println("db
= " + db); // print value of db
System.out.println("dc
= " + dc); // print value of dc
System.out.println("dd
= " + dd); // print value of dd
System.out.println("de = "
+ de); // print value of de
} //
end of main method
} // end of class
OUTPUT: