Home Java Jdk7 Arithmetic Operators in java 7



Arithmetic Operators in java 7
Posted on: December 19, 2012 at 12:00 AM
In this section you will learn about the Arithmetic operators. This is one type of operators.

Arithmetic Operators in java 7

In this section you will learn about the Arithmetic operators. This is one type of operators.

Arithmetic Operators :

Arithmetic operators are the most commonly used operator in our expressions. We use these kind of operators in our mathematical expression. They work same as we use in algebra.

Arithmetic operators are used to perform addition, subtraction, multiplication, and division. Suppose X and Y are two numeric variables.

+ (additive operator) this operator is used for adding two numbers as well as used for String concatenation. (X+Y)

- (Subtraction operator) This operator is used for subtracting the values. (X-Y)

* (Multiplication operator) It is used to multiply values. (X*Y)

/ (Division operator) This operator is used where you want to divide some values. (X/Y)

% (Remainder operator) - This is also called modulus operator. It returns remainder. (X%Y)

Other arithmetic operators -

++ (increment) - This operator increments the value by 1. (X++)
-- (decrement) -
This operator decrements the value by 1. (X--)

Example :

package operator;

class ArithmaticOperator {
	public static void main(String[] args) {
		int x = 100;
		int y = 20;
		int sum, sub, mul, mod;
		double div;

		sum = x + y; // using Additive operator
		sub = x - y; // using Subtraction operator
		mul = x * y; // using Multiplication operator
		div = x / y; // using Division operator
		mod = x / y; // using Remainder operator
		
		System.out.println("Value of x = " + x);
		System.out.println("Value of y = " + y);
		System.out.println("Sum of x and y using Additive operator = " + sum);
		System.out.println("Subtraction of x and y using Subtraction operator = "
						+ sub);
		System.out.println("Multiplication of x and y using Multiplication operator = "
						+ mul);
		System.out.println("Division of x and y using Additive operator = "
				+ div);
		System.out.println("Remainder of x and y using Remainder operator = "
				+ mod);
		
		x++; // increment operator
		y--; // decrement operator
		
		System.out.println("Incrementing x by using increment operator = " + x);
		System.out.println("Decrementing y by using decrement operator = " + y);
	}
}

Output :

Value of x = 100
Value of y = 20
Sum of x and y using Additive operator = 120
Subtraction of x and y using Subtraction operator = 80
Multiplication of x and y using Multiplication operator = 2000
Division of x and y using Additive operator = 5.0
Remainder of x and y using Remainder operator = 5
Incrementing x by using increment operator = 101
Decrementing y by using decrement operator = 19

Related Tags for Arithmetic Operators in java 7:


More Tutorials from this section

Ask Questions?    Discuss: Arithmetic Operators in java 7  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.