Home » Java Basics » operators » Arithmetic Operators

About Ilias Tsagklis

Ilias is a software developer turned online entrepreneur. He is co-founder and Executive Editor at Java Code Geeks.

Arithmetic Operators

With this example we are going to demonstrate how to use the arithmetic operators in Java. The arithmetic operators supported by the Java programming language are the Additive operator (also used for String concatenation), the Subtraction operator, the Multiplication operator, the Division operator, and the Remainder operator. In short, to use the arithmetic operators you should:

  • Use the Additive operator to add variables.
  • Use the Subtraction operator to subtract variables.
  • Use the Multiplication operator to multiply variables.
  • Use the Division operator to divide variables.

Let’s take a look at the code snippet that follows:  

package com.javacodegeeks.snippets.basics;

public class ArithmeticOperatorsExample {
	
	public static void main(String[] args) {
		 
		int i = 30 + 20;
		int j = i - 5;
		int k = j * 2;
		double l = k / 6;
		 
		System.out.println("i = " + i);
		System.out.println("j = " + j);
		System.out.println("k = " + k);
		System.out.println("l = " + l);
		
	}

}

Output:

i = 50
j = 45
k = 90
l = 15.0

  
This was an example of how to use the arithmetic operators in Java.

Do you want to know how to develop your skillset to become a Java Rockstar?

Subscribe to our newsletter to start Rocking right now!

To get you started we give you our best selling eBooks for FREE!

 

1. JPA Mini Book

2. JVM Troubleshooting Guide

3. JUnit Tutorial for Unit Testing

4. Java Annotations Tutorial

5. Java Interview Questions

6. Spring Interview Questions

7. Android UI Design

 

and many more ....

 

Receive Java & Developer job alerts in your Area

 

Subscribe
Notify of
guest

This site uses Akismet to reduce spam. Learn how your comment data is processed.

0 Comments
Inline Feedbacks
View all comments