User Story
Write Apex code to compute the sum of two numbers.
Expected Outcome
The sum of 4 and 8 is 12
Solution
Integer num1 = 4;
Integer num2 = 8;
Integer sum = num1 + num2;
System.debug('The sum of ' + num1 + ' and ' + num2 + ' is ' + sum);
Explanation
In this example, we define two variables num1 and num2 and assign them the values 4 and 8, respectively.
We then create a third variable sum and assign it the value of num1 + num2, which calculates the sum of the two numbers.
Finally, we use the System.debug() method to print out a message that displays the values of the two numbers and their sum.
You can adjust the values of num1 and num2 to calculate the sum of any two numbers you want.
Video
Video does not exists.