operators
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 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 the
Additiveoperator to add variables. - Use the
Subtractionoperator to subtract variables. - Use the
Multiplicationoperator to multiply variables. - Use the
Divisionoperator 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.
Ilias Tsagklis
Ilias is a software developer turned online entrepreneur. He is co-founder and Executive Editor atJava Code Geeks.



