Java integer FAQ: How do I add two Java integers (Java
Answer: Just use the Java addition operator, the plus sign (
+), to add two integers together.
Here's a quick example: If you have to drive 23 miles east, then 14 miles north, what is the total distance you had to drive?
int distanceEast = 23; int distanceNorth = 14; int totalDrivingDistance = distanceEast + distanceNorth;
14 are two Java
int (integer) fields, and the
totalDrivingDistance will contain the sum of those two values.