Java arithmetic operators example.

Java arithmetic operators example.


Posted in : Core Java Posted on : October 9, 2010 at 5:39 PM Comments : [ 0 ]

In this section, you will see the implementation of arithmetic operator in java.

Java arithmetic operators example.

In this example, you will see the use of arithmetic operator in java. The arithmetic operator is used for mathematical calculation.

In this java program there is a java class name ArithmeticOperater. It has five method  and two integer variable for arithmetic calculation.

additionOperator() -- Use  +  (addition) operator.  Returns addition of two number.

subtrationOperator() -- Use  - (subtraction) operator.  Returns subtraction two number.

multiplicationOperator() --  Use *  (multiplication) operator.  Returns multiplication of two number.

divisionOperator() -- Use / (division) operator.  Returns dividend  of two number.

moduloOperator() --  Use % (modulo) operator.  Returns reminder after division of two number.

Code:

AssignmentOperater.java
package com.devmanuals;

public class ArithmeticOperater {
	int num = 234;
	int num1 = 200;

	public void additionOperator() {
		System.out.println("Use of addition operator.");
		System.out.println("Addition of two number : " + (num + num1) + "\n");
	}
	public void subtractionOperator() {
		System.out.println("Use of subtraction operator.");
		System.out
			.println("Subtraction of two number : " + (num - num1)+ "\n");
	}
	public void multiplicationOperator() {
		System.out.println("Use of multiplication operator.");
		System.out.println("Multiplication of two number : " + (num * num1)+ "\n");
	}
	public void divisionOperator() {
		System.out.println("Use of division operator.");
		System.out.println("Division of two number : " + (num / num1) + "\n");
	}
	public void moduloOperator() {
		System.out.println("Use of modulo operator.");
		System.out.println("Modulo of two number : " + (num % num1) + "\n");
	}
	public static void main(String[] args) {
		ArithmeticOperater obArithmeticOperater = new ArithmeticOperater();
		obArithmeticOperater.additionOperator();
		obArithmeticOperater.subtractionOperator();
		obArithmeticOperater.multiplicationOperator();
		obArithmeticOperater.divisionOperator();
		obArithmeticOperater.moduloOperator();
	}
}
Output:
Use of addition operator.
Addition of two number : 434

Use of subtraction operator.
Subtraction of two number : 34

Use of multiplication operator.
Multiplication of two number : 46800
 
Use of division operator.
Division of two number : 1

Use of modulo operator.
Modulo of two number : 34

Download this code.

Go to Topic «PreviousHomeNext»

Your Comment:


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

 
Tutorial Topics