Operator | Operation | Example |
+ | Addition | 2+3 is 5 |
- | Subtraction | 8-2 is 6 |
* | Multiplication | 2*5 is 10 |
/ | Division | 8/8 is 1 |
% | Modulo | 15%2 is 1 |
Example Program
class binaryoperatorexample
{
public static void main(String args[])
{
int a=10,b=5,c,d,e,f,g;
c=a+b;
d=a-b;
e=a*b;
f=a/b;
g=a%b;
System.out.println("Addition:"+c);
System.out.println("Subtraction:"+d);
System.out.println("Multiplication:"+e);
System.out.println("Division:"+f);
System.out.println("Modulo:"+g);
}
}
Please make sure to include all the necessary header files before compiling the program. The output of the program will be as below.
Addition: 15
Subtraction: 5
Multiplication: 50
Division: 2
Modulo: 0
No comments:
Post a Comment