How to Use Arithmetic expression in JAVA

Hello Coders !!!
Today, I'm going to start our Second Project from the "Series of Small JAVA Projects" to enlighten JAVA basics and make you understand by writing codes and executing them.
So, Let's start with today's topic 'How to Use Arithmetic expression in JAVA'
For Executing the code I'm going to use an IDE (Integrated Development Environment) called IntelliJ IDEA to run your code. This is one of the best IDE and very Smart IDE to help you write faster code in JAVA. Just Install its community version from its official website and start using it.
Steps to Create New Project in IntelliJ Idea as follows:-
---> Go to File > New > Project > Select Java > click Next >...
> check on Create project from template > & give your Project Name (I'm giving Second Project) > click on Finish.
---> Now click on a project folder and see the folder name 'src', hit right click on that folder and go to New then click on Package and give the name (I'm giving 'Arithmetic' for this project) and hit Enter.
Now a new package will be created, then go to 'Print' & right-click, go to New & click on JAVA Class, go ahead and give a name for the JAVA class (I'm giving the name for this project 'Maths') and hit Finish.
Here we go, Our Project, Package & JAVA class is created.
Here's the Code!
package Airthmetic;
public class Maths {
public static void main(String args [])
{
int num1 = 5, num2 = 7, Result1, Result2, Result3, Result5;
Result1 = num1 + num2;
Result2 = num1 * num2;
Result3 = num1 - num2;
float Result4 = num2 / num1;
Result5 = num2 % num1;
System.out.println("Addition of Result is " + Result1);
System.out.println("Multiplication of Result is " + Result2);
System.out.println("Subtraction of Result is " + Result3);
System.out.println("Division of Result is " + Result4);
System.out.println("Modulus of Result is " + Result5);
}
}
/* If you aren't able to see full code on your mobile device, just rotate your screen to landscape mode. */
Tips:- After writing the code for the first time you need to "RUN" the code by hitting right-click and click on 'Run', only for the first time, after this, you can just click on the Run button available on Right-Hand Top corner.
This is 'How to Use Arithmetic expression in JAVA'.& this is how we solve some maths in JAVA. Just Install IntelliJ IDEA from the link https://bit.ly/2RHmQRC and start coding.
For any queries you can just ask me in the comment below, I'll help you to the best of my knowledge.
Hope you like it. Stay Tuned, A lot more series of small JAVA projects are coming.
Don't forget to see our next project posting every other day.
Give your Love & Support.
HAPPY CODING !!!
Comments
Post a Comment