Java Simple Calculator | Java example

[et_pb_section admin_label=”section”][et_pb_row admin_label=”row”][et_pb_column type=”4_4″][et_pb_text admin_label=”Text” background_layout=”light” text_orientation=”left” use_border_color=”off” border_color=”#ffffff” border_style=”solid”]

Java simple calculator :

We now have learnt how to take input from user and make arthematic operations by making use of variables.Now we will accept two numbers from user and process them according to operators.


First let’s deal with accepting numbers so for that declare two variables

public static int a;
public static int b;

Now a result variable

public static int result;


Now accept first number

System.out.println("Enter first number");

Store to user input in variable a

a = scan.nextInt();

Same as first value do for second one

System.out.println("Enter second number");
b = scan.nextInt();


Calculator with addition functionality:

Scanner scan = new Scanner(;

System.out.println("Enter first number");

a = scan.nextInt();

System.out.println("Enter second number");

b = scan.nextInt();

result = a + b;


java simple calculator


If you have any query on java simple calculator let us know in the comment section below.

For more interesting tutorials on java like, share this tutorial.




Show Buttons
Hide Buttons
Read previous post:
Java Scanner Class – Accept User Input | Java example

  In programming we need to accept user inputs process them and provide result.We use Scanner class to get user...