1. Java Arithmetic Operators
2. Java Assignment Operators
3. Java Increment and Decrement Operators
4. Java Relational Operators
5. Java Boolean Operators
6. Java Conditional Operators
Java Arithmetic Operators
The Java Programming Language has includes Five Simple Arithmetic Operators like are
+ (ADDITION),
- (SUBTRACTION),
* (MULTIPLICATION),
/ (DIVISION),
% (MODULO).
The following table summarizes the Binary Arithmetic Operators in the Java programming language.
USE | RETURNS TRUE IF |
OP1 + OP2 | OP1 Added To OP2 |
OP1 – OP2 | OP2 Subtracted From OP1 |
OP1 * OP2 | OP1 Multiplied With OP2 |
OP1 / OP2 | OP1 Divided By OP2 |
OP1 % OP2 | Computes the Remainder of Dividing OP1 By OP2 |
Example Source Code:
public class ArithmeticProg
{
public static void main(String[] args)
{
//A Few Numbers
int i = 10;
int j = 20;
double x = 10.5;
double y = 20.5;
//Adding Numbers
System.out.println(“Adding”);
System.out.println(” i + j = ” + (i + j));
System.out.println(” x + y = ” + (x + y));
//Subtracting Numbers
System.out.println(“Subtracting”);
System.out.println(” i – j = ” + (i – j));
System.out.println(” x – y = ” + (x – y));
//Multiplying Numbers
System.out.println(“Multiplying”);
System.out.println(” i * j = ” + (i * j));
System.out.println(” x * y = ” + (x * y));
//Dividing Numbers
System.out.println(“Dividing”);
System.out.println(” i / j = ” + (i / j));
System.out.println(” x / y = ” + (x / y));
//Computing The Remainder Resulting
//From Dividing Numbers
System.out.println(“Modulus”);
System.out.println(” i % j = ” + (i % j));
System.out.println(” x % y = ” + (x % y));
}
}
JAVA Tutorial PART 2 - Arithmetic Operators
0 comments:
Post a Comment