by Dinesh Thakur Category: Operators and Expressions

The Arithmetic operators are used to perform arithmetic operations. The Arithmetic operators are binary operators that work with integers, floating point numbers and even characters (i.e. they can be used with any primitive type except the boolean).

There are five arithmetic operators available in Java which include addition (+), subtraction (-), multiplication (*), division (/) and modulus (%) operator. The modulus operator tells us what would be the remainder after integer division is performed on a particular expression. Unlike C/C++, the modulus operator can also be applied to floating point values. The rest of the operators have same meaning as they have in mathematics.

The operands acted on by arithmetic operators must represent numeric values. Thus the operands can be integer quantities, floating point quantities or characters. The Arithmetic operators when used with characters operate on Unicode values of the characters.

The result of division of one integer quantity by another is referred to as integer division as this operation results in a quotient without a decimal point. On the other hand, if division is carried out with two floating point numbers or with one floating point and one integer number, the result will be a floating point quotient.

//Program Showing Arithmetic Operations

public class ArithmeticOperators

{

public static void main (String[] args)

{

float x=10.5f ,y=2.3f ;

System.out.println(" x+y = " + (x+y));

System.out.println(" x-y = " + (x-y));

System.out.println(" x*y = " + (x*y));

System.out.println(" x/y = " + (x/y));

System.out.println(" x%y = " + (x%y));

}

}

Java Example to Perform Arithmetic Operation Using Scanner Class.

import java.util. *;

class ArithmeticOperatorsUsingScanner

{

public static void main(String args[])

{

int a,b;

Scanner scan=new Scanner(System.in);

System.out.print("Enter the Value of a : ");

a=scan.nextInt();

System.out.print("Enter the Value of b : ");

b=scan.nextInt();

System.out.println("Addition is : " +(a+b));

System.out.println("Subtraction is : "+( a-b));

System.out.println("Multiplication is : "+( a*b));

System.out.println("Division is : "+( a/b));

System.out.println("Modulus is : "+( a%b));

}

}

About Dinesh Thakur

Dinesh Thakur holds an B.SC (Computer Science), MCSE, MCDBA, CCNA, CCNP, A+, SCJP certifications. Dinesh authors the hugely popular Computer Notes blog. Where he writes how-to guides around Computer fundamental , computer software, Computer programming, and web apps. For any type of query or something that you think is missing, please feel free to Contact us.

Search Content

Popular Article

#### Constant - What is Constant? Type of Constant

#### Java Operator

#### What is Identifiers,Literals,Operator and Separators

#### Shift Operators in Java Examples

#### Logical Operators in Java Examples

#### Assignment Operator in Java Example

#### Conditional Operator in Java with Example

#### Bitwise Complement Operator Example in Java

#### Increment and Decrement Operators in Java Examples

#### Arithmetic Operators in Java Examples

#### Explicit Type Conversion (Type Casting)

#### Bitwise Operators in Java Example

#### Bitwise AND, OR, and XOR Operators in Java Example

#### Relational Operators in Java Example

#### Implicit Type Conversion in Java Example

#### Java Break Statement with Label Example

#### Mathematical Operations in Java Example

#### Compound Assignment Operators in Java Example

#### Java Continue Statement Example

#### Area of Triangle in Java Example

#### Java Arithmetic Operators Example

#### Java Continue With Label Example

#### Break Statement Java Example

#### Comparison Operators in Java Example

#### Java Break Statement Example

Basic Courses

Advance Courses