Arithmetic Operators in Java20 Apr 2025 | 4 min read The ability to do basic mathematical calculations on numeric data types makes arithmetic operators one of Java's most often-used operators. Java has multiple kinds of arithmetic operators, each with a unique set of features and syntax. The numerous kinds of arithmetic operators in Java will be covered in this tutorial, along with more complex examples to help you learn how to use them. 1. Addition Operator (+)To combine two numerical numbers, use the addition operator. All numeric data types, including integers, floating-point numbers, and even characters, can be utilised with it. Here's an illustration: Explanation In this illustration, we'll define two integer variables, a and b, add their values together using the addition operator, and then assign the result to c. 2. Subtraction Operator (-)To subtract one numeric number from another, use the subtraction operator. All numeric data types, including integers and floating-point values, can be utilised with it. Here's an illustration: Explanation In this example, we create two integer variables, a and b, subtract b from a, and then assign the result to the variable c. 3. Multiplication Operator (*)To combine two numerical numbers, use the multiplication operator. All numeric data types, including integers and floating-point values, can be utilised with it. Here's an illustration: Explanation In this example, we declare two integer variables, a and b, multiply their values using the multiplication operator, and then assign the outcome to the third variable, c. 4. Division Operator (/)To divide one numerical number by another, use the division operator. All numeric data types, including integers and floating-point values, can be utilised with it. Here's an illustration: Explanation In this example, we declare two integer variables, a and b, divide them by one another using the division operator, and then assign the outcome to the variable c. It's vital to remember that when two numbers are divided, the outcome will also be an integer, and any residual will be thrown away. For instance: 5. Modulus Operator(%)To determine the remaining part of a division operation, use the modulus operator. All numeric data types, including integers and floating-point values, can be utilised with it. Here's an illustration: Explanation The modulus operator is used in this example to discover the remaining after dividing the two integer variables a and b, and the result is then assigned to the variable c. The leftover in this instance is 1. 6. Increment Operator (++)When using the increment operator, a numerical variable's value is raised by 1 in value. All numeric data types, including integers and floating-point values, can be utilised with it. 7. Decrement Operator (--)When a numerical variable's value has to be reduced by 1, the decrement operator is used. All numeric data types, including integers and floating-point values, can be utilised with it. Here's an illustration: In this instance, we declare an integer variable a and decrement it by 1 using the decrement operator. 8. Operators for Compound AssignmentsCompound assignment operators enable you to execute a computation and assign the result to a variable in a single statement by combining an arithmetic operator with an assignment operator. In Java, there are several varieties of compound assignment operators, including:
Next TopicTypes of JDBC Drivers in Java |
To add all special characters to the end of a string in Java, it's necessary to iterate through the input string, identify the alphanumeric letters, and then rearrange them so that the special characters are at the end. Java's built-in character classification methods can be used...
5 min read
Java, a widely used programming language, is known for its robustness and protection capabilities. However, even in the maximum cautiously crafted programs, mistakes can occur. One common type of error is the "Illegal Argument Exception." In this section, we are going to explore what this exception...
4 min read
It is a problem frequently asked in interviews of top IT companies like Google, Amazon, TCS, Accenture, etc. To solve the problem, one wants to check the logical ability, critical thinking, and problem-solving skills of the interviewee. So, in this section, we are going to solve...
5 min read
In this section, we will create Java programs that print India map pattern using for loop, while loop, and using obfuscated code. IndiaMapPattern1.java public class IndiaMapPattern1 { public static void main(String args[]) { int a =10, b = 0, c = 10; // The encoded string after removing first 31 characters // Its individual...
4 min read
In Java, ServerSocket can be defined as a type of class which is majorly utilized for providing implementation of the server-side socket connection of client or server. Also, the socket connection of the client or client is fully independent of system. Let us understand about ServerSocket class...
20 min read
A positive integer array with an equal amount of digits for each integer is given. The number of distinct digits that occur in the same location in two integers is known as the digit difference between them. The total of the digit differences between each pair of...
7 min read
The repaint method in java is accessible in java.applet.Applet class is a final method utilized at whatever point we need to call update technique alongside the call to paint method; the call to refresh method clears the ongoing window, plays out an update, and a short...
3 min read
An abundant number, also known as an excessive number, is a positive integer for which the sum of its proper divisors (excluding the number itself) is greater than the number itself. In other words, an abundant number is a number that is "abundant" in divisors. Let's explore...
4 min read
Contextual keywords formerly known as restricted identifiers and restricted keywords. contextual keywords are identified based on where they will appear in the syntactic grammar. These are the keywords that provides the specific meaning in the code. These are not reserved keywords like abstract, new, final, try,...
3 min read
In Java, inheritance enables a class to adopt behaviors and functions from another class. The class from which the functionalities and behaviours are inherited is known as the base class or parent class or superclass. The receiver class is often known as a child class,...
4 min read
We request you to subscribe our newsletter for upcoming updates.
We provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India