Embed presentation
Download to read offline
![public class ArithmeticOperatorDemo {
// Demonstrate the basic arithmetic operators.
public static void main(String args[]) {
// arithmetic using integers
System.out.println("Integer Arithmetic");
int i = 1 + 1;
int n = i * 3;
int m = n / 4;
int p = m - i;
int q = -p;
System.out.println("i = " + i);
System.out.println("n = " + n);
System.out.println("m = " + m);
System.out.println("p = " + p);
System.out.println("q = " + q);
// arithmetic using doubles
System.out.println("nFloating Point Arithmetic");
double a = 1 + 1;
double b = a * 3;
double c = b / 4;
double d = c - a;
double e = -d;
System.out.println("a = " + a);
System.out.println("b = " + b);
System.out.println("c = " + c);
System.out.println("d = " + d);
System.out.println("e = " + e);
}
}](https://image.slidesharecdn.com/publicclassarithmeticoperatordemo-170822044936/85/Public-class-arithmetic-operatordemo-1-320.jpg)
This Java program demonstrates basic arithmetic operators by performing integer and floating point arithmetic. It defines variables i through q to hold the results of integer arithmetic operations like addition, multiplication, division, and subtraction. It then defines variables a through e to hold the results of similar floating point arithmetic operations. The values of all variables are printed to show the results.
![public class ArithmeticOperatorDemo {
// Demonstrate the basic arithmetic operators.
public static void main(String args[]) {
// arithmetic using integers
System.out.println("Integer Arithmetic");
int i = 1 + 1;
int n = i * 3;
int m = n / 4;
int p = m - i;
int q = -p;
System.out.println("i = " + i);
System.out.println("n = " + n);
System.out.println("m = " + m);
System.out.println("p = " + p);
System.out.println("q = " + q);
// arithmetic using doubles
System.out.println("nFloating Point Arithmetic");
double a = 1 + 1;
double b = a * 3;
double c = b / 4;
double d = c - a;
double e = -d;
System.out.println("a = " + a);
System.out.println("b = " + b);
System.out.println("c = " + c);
System.out.println("d = " + d);
System.out.println("e = " + e);
}
}](https://image.slidesharecdn.com/publicclassarithmeticoperatordemo-170822044936/85/Public-class-arithmetic-operatordemo-1-320.jpg)