How to Do Addition of Variables in Java
Programming languages like Java have mathematical functions built in, such as addition and subtraction. These mathematical functions can be used to add numbers together, which is useful when performing calculations inside of your software. You can add two variables together in Java by using the addition symbol with the two variables.
Instructions
-
-
1
Open your Java program in your environment editor of choice.
-
2
Declare the first number you want to add, such as the number "10" by typing "int x = 10;" into the program.
-
-
3
On a new line, declare the second number, such as "5" by typing "int y = 5;" into the program.
-
4
Type, on a new line, "int z = x + y" to add the two variables "x" and "y" together and set the result equal to the variable "z."
-
1