How to Create simple java calculator [2020]

One of the first programs that a beginner might consider while learning java is to create a simple java calculator.

In this tutorial, we will learn how to create a simple java calculator. We will use simple notepad and command prompt to do this.

In order to make simple java calculator, you need to have java installed in your system. Also make sure, your environment variables are set properly.

Write Code for simple java calculator:

import java.util.Scanner;

class SimpleCalculator{
   public static void main(String args[]){
      Scanner MyScanner = new Scanner(;
      double No1,No2,Answer;
      System.out.print("Enter no 1 : ");
      No1 = MyScanner.nextDouble();

      System.out.print("Enter no 2 : ");
      No2 = MyScanner.nextDouble();

      Answer = No1 + No2;
      System.out.println("Addition Is : ");

      Answer = No1 - No2;
      System.out.println("Subtraction Is : ");

      Answer = No1 / No2;
      System.out.println("Division Is : ");

      Answer = No1 * No2;
      System.out.println("Multiplication Is : ");

So after writing this code inside notepad save this file as Once you save this file, then open up command prompt and navigate to the folder where you had saved In my case it is at desktop, so i will type the below commands to navigate to my desktop and run this program.

Running our simple java calculator:

Open up cmd and type the below commands.

cd desktop
java SimpleCalculator
How to Create simple java calculator [2020]

Once you’ve typed the above command then you will see something like the above picture. Then enter no 1 and enter no 2 and it will print it’s addition, subtraction, multiplication and division.

I know this is a very simple java calculator and you probably make it so far. So if you have any confusion, feel free to leave a comment and i will answer that.

In order to understand each concept in detail, you should make java programs like this.

So make sure to understand each line of it as it uses a very simple and clear stuff.

There are plenty of other things that you should know and by understanding this program, for example you’ve learned how to run a java program in cmd. You’ve also learned how to make a class in java, also one more thing keep in mind that you should name your file the same as your main class name is. Also you’ve learned how to take user input in java.

Also how to print anything on the console in java. You can learn plenty of things by practicing on concepts that you’ve learned in this tutorial.

So make sure to practice on things like how to take input in java, how to print something on screen in java, how to name your java file and the most important one is that how to run java program in cmd.

If you have any confusion feel free to leave a feedback and i will get back to you. Happy Coding!

Leave a Reply

Your email address will not be published. Required fields are marked *