Java Arithmetic Operators

By Kunal Kapoor
19-04-2018
418

Arithmetic operators are used in mathematical expressions in the same way that they are used in algebra

 

 


eg



myClass.java:

package arithematic_operations;

public class myClass {

	public static void main(String[] args) {

		int alpha = 1 + 1;
		int beta = alpha * 3;
		int gamma = beta / 4;
		int oscar = gamma - alpha;
		int charlie = -oscar;
		System.out.println("alpha = " + alpha);
		System.out.println("beta = " + beta);
		System.out.println("gamma = " + gamma);
		System.out.println("oscar = " + oscar);
		System.out.println("charlie = " + charlie);
	
		// using doubles
		System.out.println("\n"+"double data types");
		double double_a = 1 + 1;
		double double_b = double_a * 3;
		double double_c = double_b / 4;
		double double_d = double_c - alpha;
		double double_e = -double_d;
		System.out.println("double_a = " + double_a);
		System.out.println("double_b = " + double_b);
		System.out.println("double_c = " + double_c);
		System.out.println("double_d = " + double_d);
		System.out.println("double_e = " + double_e);

	}

}

output:

alpha = 2
beta = 6
gamma = 1
oscar = -1
charlie = 1

double data types
double_a = 2.0
double_b = 6.0
double_c = 1.5
double_d = -0.5
double_e = 0.5


Operator symbol

Operator

+

Addition

-

Subtraction

*

Multiplication

/

Division

++

Increment

--

Decrement

%

Modulus



Related Tutorials