X
    Categories: java

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.in);

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

a = scan.nextInt();

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

b = scan.nextInt();

result = a + b;

System.out.println(result);

 

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.

 

 

[/et_pb_text][/et_pb_column][/et_pb_row][/et_pb_section]

abhishek:
Related Post

This website uses cookies.