How to Do Addition in Java
Simple mathematical calculations are a part of any computer program. Java uses the same addition operator as other programming languages. You must create a variable that contains the result of the Java addition. The result can be used for further calculations or you can display the result to the user.
Instructions
-
-
1
Right-click the Java source code file, and select "Open With." Click your Java compiler to open the code in your editor.
-
2
Create a variable to hold the calculation results. The following code creates a variable for your Java calculation:
int result = 0;
-
-
3
Perform your addition calculation. The following code shows you how to perform addition in Java:
result = 2+2;
-
4
Print the result to your user. The following code shows you how to display the calculation result to the reader's screen:
System.out.println(result);
-
1