In this tutorial we will learn how to use Arithmetic Operators, Mathematical operations in Java. we will create separate non static methods for each operation like addition, subtraction, multiplication, and division and we call those in main method. If you want to follow along by watching below is link for java basic calculator where we have used arithmetic operation by creating method. Step be Step tutorial is in English and Hindi Language.
Java Basic Calculator Video Tutorial in English
Now to call method in main class create instance of class . since we are using not static method we have to create instance of class. Syntax is name of class then variable then we use new word and class name then parenthesis. now if you use dot operator after that variable we will get all method which we can able to access. we want to use Add method so lets select it and check in output. we can observe we have result.
Now lets do Subtraction by creating non static method, we have created method and created variable , a, b, and result . All have data type as integer and we are calling in main methods.
Now lets try out multiplication everything is same but in the result variable we have just changed operation.
Now we are doing last operation, division. so we are doing same thing created three variables and calling in the result we have changed operation we are doing division and we are calling method in main .