operators

Arithmetic Operators

Photo of Ilias TsagklisIlias TsagklisNovember 11th, 2012Last Updated: August 20th, 2013
0 146 1 minute read

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 theAdditive operator (also used for String concatenation), theSubtraction operator, theMultiplication operator, theDivision operator, and theRemainder operator. In short, to use the arithmetic operators you should:

  • Use theAdditive operator to add variables.
  • Use theSubtraction operator to subtract variables.
  • Use theMultiplication operator to multiply variables.
  • Use theDivision 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 = 50j = 45k = 90l = 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 aJava Rockstar?
Subscribe to our newsletter to start Rockingright now!
To get you started we give you our best selling eBooks forFREE!
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 ....
I agree to theTerms andPrivacy Policy

Thank you!

We will contact you soon.

Photo of Ilias TsagklisIlias TsagklisNovember 11th, 2012Last Updated: August 20th, 2013
0 146 1 minute read
Photo of Ilias Tsagklis

Ilias Tsagklis

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

Related Articles

Subscribe
Notify of
guest
I agree to theTerms andPrivacy Policy
The comment form collects your name, email and content to allow us keep track of the comments placed on the website. Please read and accept our website Terms and Privacy Policy to post a comment.

I agree to theTerms andPrivacy Policy
The comment form collects your name, email and content to allow us keep track of the comments placed on the website. Please read and accept our website Terms and Privacy Policy to post a comment.