Codementor Events

Java tutorial 3 - Operators

Published Dec 18, 2020Last updated Dec 20, 2020
Java tutorial 3 - Operators

In the last tutorial, we tried to understand what a variable is. In this 3rd tutorial, we will aim at understanding the concept of operators.

In case you haven't read the previous tutorial, I recommend you to first go through it and then continue with this one. I'll wait for you.

DRUM ROLL

So what are operators?
Operators in Java are symbols which is used to perform operations on variables. For example: +, -, *, / etc.

I am going to begin with the same program that I used in the last tutorial

public class Main {
    public static void main(String[] args) {
        int a = 2;
        int b = 3;
        int c = a + b;
        System.out.println(c);
    }
}

Here the + symbol is called the operator

We can also add, subtract, multiply, divide, and take modulus as shown in the example given below.

    public static void main(String[] args) {
        int a = 10;
        int b = 2;

        int c = a + b;  // Addition
        int d = a - b;  // Subtraction
        int e = a * b;  // Multiplication
        int f = a / b;  // Division
        int g = a % b;  // Modulus

        System.out.println(c);
        System.out.println(d);
        System.out.println(e);
        System.out.println(f);
        System.out.println(g);

    }

Output:

12
8
20
5
0

And there we are

I think that you were able to understand what operators are. In case you have any doubts, I am happy to help you out.

In the next part, we will learn about if else statements. Hope to see you there too.
That`s it for this blog. If you wanna become a great programmer, I am there to help.

You can see my profile by clicking on my name below.

Discover and read more posts from Aniket Malik
get started
post commentsBe the first to share your opinion
Show more replies